select multiple wild cards...

  • 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.

  • 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[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • 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

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply