Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Filtering character in a query
Message
 
 
À
28/02/2011 22:02:30
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01502169
Message ID:
01502172
Vues:
76
This message has been marked as the solution to the initial question of the thread.
Try

where FirstName LIKE 'S[_]SH%' ([ are the escape characters)

Also, in SQL Server most installations are case insensitive, so using UPPER function makes your query non sargable. If you want to be 100% sure it will work you can use COLLATE keyword to use non case-sensitive collation.

So, essentially, you can replace _ with [_] when you create your string to check.

See also http://msdn.microsoft.com/en-us/library/ms187489.aspx

and there Searching for Wildcard Characters

>I just discoverd something I was not aware. The _ character is used as a filtering character, such as a wild card, when doing a query. The following:
>
>
>DECLARE @LXListFirstName Varchar(16)
>
>SET @LXListFirstName='S_SH%'
>
>SELECT Member.Numero
> FROM Member
> WHERE UPPER(Member.FirstName) LIKE @LXListFirstName
> ORDER BY Member.LastName,Member.FirstName 
>
>
>...will find all records having S as the first character and SH for the 3rd and 4th character no matter what is the second letter. So, it found results such as:
>
>Sushil
>Sasha
>Sushma
>Sushell
>Sushi
>
>How can I turn that OFF? Basically, I really needed to find S_Sh as is and not all those records.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform