Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

select multiple wild cards... Expand / Collapse
Author
Message
Posted Monday, March 7, 2011 12:55 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Tuesday, November 19, 2013 7:04 AM
Points: 72, Visits: 172
user will click on a tab 'ABC','DEF'... and when they do i need to query for all last names that begin with A%, B%, C% or D%, E%, F% can i do this in one query or do i have to use 3 queries to retrieve all the rows that meet the criteria.
Post #1074422
Posted Monday, March 7, 2011 1:00 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 11:09 AM
Points: 7,021, Visits: 12,920
You could use
WHERE yourColumn LIKE 'A%' OR yourColumn LIKE 'B%' OR yourColumn LIKE 'C%'

or just create a view with an additional column
CASE WHEN yourColumn LIKE 'A%' OR yourColumn LIKE 'B%' OR yourColumn LIKE 'C%' THEN 1
WHEN yourColumn LIKE 'D%' OR yourColumn LIKE 'E%' OR yourColumn LIKE 'F%' THEN 2
ELSE 3 END AS Grp

Then you could simply use WHERE Grp=1.




Lutz
A pessimist is an optimist with experience.

How to get fast answers to your question
How to post performance related questions
Links for Tally Table , Cross Tabs and Dynamic Cross Tabs , Delimited Split Function
Post #1074428
Posted Monday, March 7, 2011 5:06 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, July 8, 2014 2:57 AM
Points: 369, Visits: 1,208
Select LastName from MyTable
Where LastName like '[A-C]%'

Select LastName from MyTable
Where LastName like '[D-F]%'

or

Select LastName from MyTable
Where LastName like '[ABC]%'

Select LastName from MyTable
Where LastName like '[DEF]%'

...

It would be good to have an index on LastName. Check execution plan and logical reads.

Hope this helps.


_____________________________________________________
Microsoft Certified Master: SQL Server 2008
XDetails Addin - for SQL Developers
blog.sqlxdetails.com - Transaction log myths
Post #1074545
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse