开发者

contains clause sql server

Assume that I had the following t-sql:

开发者_高级运维

select * from customer where contains(suburb, '"mount*"').

Now it brings back both: "Mount Hills" and "Blue Mountain". How do I strict it to search only the very beginning of the word which in this case is only "Mount Hills"?

thanks


'contains' is used for exactly that. Use

select * from customer where charindex('mount', suburb)=1

or

select * from customer where suburb like 'mount%'

but that's slower.


Your query works correctly, you asked server "give me all record where ANY word in column 'suburb'" starts with 'mount'. You need to be more specific what are you trying to accomplish. Match beginning of the entire value stored in column? LIKE is your friend then.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜