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.
精彩评论