Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using CONTAINS in where clause
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Application:
Web
Miscellaneous
Thread ID:
01505253
Message ID:
01505274
Views:
26
>The LIKE will find the search value at the beginning of the text only and Contains - any word that matches criteria. It means that Contains is redundant in your case.

You should use one or the other.

Contains is supposed to be more efficient on large searches. I normally use LIKE.

use LIKE '%'+@Parameter1+'%' will find anything containing the value of @Parameter1.


>
>>I have a SQL command that is executed in one of the applications I support and there is something I can't reminder. Lets take a look at a simplified version of the SQL command:
>>
>>
>>DECLARE @Parameter12 Varchar(30)
>>DECLARE @Parameter1 Varchar(30)
>>
>>SET @Parameter12='"MERCEDES*"'
>>SET @Parameter1='MERCEDES%'
>>
>>SELECT MyTable.PrimaryKey
>> WHERE Contains (MyTable.VehicleMake, @Parameter12) AND MyTable.MyTable.VehicleMake LIKE @Parameter1
>>
>>
>>When I look at the SQL today, I have been wondering what does it give more to have the Contains clause in there. The VehicleMake is full text indexed. However, because the second part of the WHERE clause is taking everything that starts with MERCEDES, I am questioning the use of the Contains syntax. The way I see it, it doesn't change anything as even if MERCEDES is contained in the VehicleMake field, the fact that the second part of the WHERE clause takes everything starting with it, it will not give me any additional records.
>>
>>Is this your understanding as well?
____________________________________

Don't Tread on Me

Overthrow the federal government NOW!
____________________________________
Previous
Reply
Map
View

Click here to load this message in the networking platform