Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question About Case Statement With This Query

Status
Not open for further replies.

lrdave36

Technical User
Joined
Jan 6, 2010
Messages
77
Location
US
Hey guys,


First, let me describe what I want to accomplish. I have a table that looks like this:


USER ID SCREEN Inquiry Change Delete
_______ ________ _______ ______ ______

2345 PR23 I C D



I want a query to display the word "ALL" if the users have I, C and D permissions.

Is this possible to do with a Case statement? Something like

CASE WHEN Inquiry = 'I" THEN 'ALL'

The problem is how can I do a CASE for multiple values? 'ALL' is not valid if they only have 'I'. Can you do nested case statements??
 
nested CASE expressions are possible, but not needed in this, um, case :-)
Code:
SELECT CASE WHEN Inquiry = 'T'
             AND Change = 'C'
             AND Delete = 'D'
            THEN 'All'
            ELSE NULL END  AS All


please note that DELETE is a reserved word, so you might need to escape it



r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top