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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nesting Case Statements.

Status
Not open for further replies.

vbjohn

Programmer
Joined
Aug 23, 2001
Messages
67
Location
US
am wondering if there is a way that we could do a nesting case statement in an SQL Query?

This is what I have now... FicaWages = CASE WHEN (UPR00900.FICAMWGS_1 + UPR00900.FICAMWGS_2) >= '84900' AND UPR00400.SBJTSSEC = 1 THEN '0' WHEN UPR00400.SBJTSSEC = 0 THEN '0' ELSE (UPR30100.GRWGPRN - (SELECT SUM(UPR30300.UPRTRXAM) FROM UPR30300 WHERE UPR30300.EMPLOYID = UPR00100.EMPLOYID AND UPR30300.PAYROLCD LIKE '3%' AND AUCTRLCD = 'UPRCC00000007')) END

What I want: FicaWages = CASE ('Sql Statement') = 'GRM' THEN CASE ('Sql Statement') => '84900' THEN ELSE END WHEN THEN ELSE END.

I hope this is clear enough.
 

You can nest Case statements. Make sure each Case statement has a corresponding End.
[tt]
Select
Col1, Col2,
NewValue=
Case
When Col1>0 Then
Case Col2
When 'X' Then 'value1'
When 'Y' Then 'value2'
When 'Z' Then 'value3'
Else 'Unknown'
End

Else
Case Col2
When 'X' Then 'value4'
When 'Y' Then 'value5'
When 'Z' Then 'value6'
Else 'Unknown'
End

End
,
Col4, Col6
From table[/tt] Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top