Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
I am trying to modify a case statement that dumps everything into the else clause to be more specific with what it returned. For example, the case statement has many conditions like this:S=Casewhen a='xx' then 'Group A'when b = 'yy' then 'Group B'This goes on for about 3 pages and then finally sayselse 'Group 800'What I would like to do is more clearly define Group 800 in the else clause and only populate it when it meets further conditions such aswhen Division NOT IN ('a','b','c','d')AND Item NOT IN ('a','b','c','d')AND Name NOT IN ('a','b','c','d')AND GROUP = 'xxx'Can I just add this to the else clause? I would like the result to include all the exclusions in the prior case statements, because those properties belong only to other groups in those case statements, and then return the rest with the additional exclusions like above. I have not seen any examples of this anywhere.Or is this not handled in a case statement at all? Thanks -SD
madhivanan
Premature Yak Congratulator
22864 Posts
Posted - 2008-09-06 : 05:00:11
Try
S=Casewhen a='xx' then 'Group A'when b = 'yy' then 'Group B'...else case when Division NOT IN ('a','b','c','d') AND Item NOT IN ('a','b','c','d') AND Name NOT IN ('a','b','c','d') AND GROUP = 'xxx' then 'Group 800' else 'some other group' endend
[/code]MadhivananFailing to plan is Planning to fail