Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


select multiple wild cards...


select multiple wild cards...

Author
Message
roy.tollison
roy.tollison
SSC Journeyman
SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)

Group: General Forum Members
Points: 86 Visits: 200
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.
LutzM
LutzM
SSCertifiable
SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)SSCertifiable (7K reputation)

Group: General Forum Members
Points: 7021 Visits: 13559
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
Vedran Kesegic
Vedran Kesegic
Old Hand
Old Hand (382 reputation)Old Hand (382 reputation)Old Hand (382 reputation)Old Hand (382 reputation)Old Hand (382 reputation)Old Hand (382 reputation)Old Hand (382 reputation)Old Hand (382 reputation)

Group: General Forum Members
Points: 382 Visits: 1255
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

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search