Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Like syntax
Message
 
To
06/03/2008 15:43:03
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Miscellaneous
Thread ID:
01299491
Message ID:
01299522
Views:
10
>>>Hi All,
>>>
>>>I have looked at the BOL, but it only shows one item per LIKE. Is this correct, or can you have multiple items per LIKE?
>>>
>>>I am trying to do an INLIST() in SQL Server. INLIST is partial matching, if you do not pad the items in the list. That is what I need to do now.
>>>
>>>Or, do I have to do fieldname LIKE 'A%' or fieldname LIKE 'D%' or fieldname LIKE 'Z%', etc?
>>>
>>>TIA
>>>Beth
>>
>>
>>SELECT * FROM YourTable WHERE fieldname LIKE '[ADZ]%'
>>
>
>Hi Borislav,
>
>Can you explain a little more on your select statement? How will that get all records starting with A or D or Z? I look at it and see get all records starting with ADZ.
>
>My sample was very basic, but more complex then BOL gives.
>
>It could be fieldname LIKE 'A%' or fieldname LIKE 'DE%' or fieldname LIKE 'ZEBRA%'
>
>Thanks,
>Beth


From BOL "Pattern Matching in Search Conditions"
Wildcard  Meaning  
%         Any string of zero or more characters.
_         Any single character.
[ ]       Any single character within the specified range (for example, [a-f]) or set (for example, [abcdef]).
[^]       Any single character not within the specified range (for example, [^a - f]) or set (for example, [^abcdef]).
So you get all records where fieldname begins with A or D or Z. For more complex searching like you describe you have to use OR.
I am not a master of LIKE command so maybe I'm wrong and there is a way to accomplish the task, but I'm not sure.
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Reply
Map
View

Click here to load this message in the networking platform