假设我有以下t-sql:包含子句sql服务器
select * from customer where contains(suburb, '"mount*"')
。
现在它带回两个:“山山”和“蓝山”。我怎样严格搜索这个词的开头,在这个例子中只是“Mount Hills”?
谢谢
假设我有以下t-sql:包含子句sql服务器
select * from customer where contains(suburb, '"mount*"')
。
现在它带回两个:“山山”和“蓝山”。我怎样严格搜索这个词的开头,在这个例子中只是“Mount Hills”?
谢谢
'contains'正好用于此。使用
select * from customer where charindex('mount', suburb)=1
或
select * from customer where suburb like 'mount%'
但这是慢。
你的查询工作正常,你询问服务器“给我所有记录哪里有任何字在'郊区'的字'开始'安装'。 你需要更具体的你想要完成什么。匹配存储在列中的整个值的开始?那就是你的朋友。
hhmm ...'mount'这个词仅仅是一个例子。实际的输入是不同的,不限于“挂载”字样。 – user384080 2010-11-04 05:32:41
难道你只是在这种情况下使用charindex(@variablename,suburb)= 1吗? – 2010-11-04 06:36:38