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


Oracle CASE statement into SQL Server


Oracle CASE statement into SQL Server

Author
Message
5280_Lifestyle
5280_Lifestyle
SSC Rookie
SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)

Group: General Forum Members
Points: 40 Visits: 325
I'm working on changing an Oracle CASE statement into a SQL Server CASE statement. I having a spot of difficulty in trying to figure out how to alter the code. It seems as though I am making it harder than it really needs to be. The Oracle code is...


(CASE
WHEN TO_CHAR(H.effdt, 'YYYY') IN ('2001','2002') THEN
DECODE (H.review_rating,
'1','Exceeded Way, Exceeded Results',
'2','Exceeded Way, Achieved Results',
'3','Exceeded Way, Did not meet Results',
'4','Achieved Way, Did not meet Results',
'5','Achieved Way, Achieved Results',
'6','Achieved Way, Exceeded Results',
'7','Did not meet Way, Exceeded Results',
'8','Did not meet Way, Achieved Results',
'9','Did not meet Way, Did not meet Results',
'Empty')

WHEN TO_CHAR(H.effdt, 'YYYY') IN ('2003','2004', '2005') THEN
DECODE (H.review_rating,
'1','Does not Meet Expectations',
'2','Partially Meets Expectations',
'3','Meets Expectations',
'4','Exceeds Expectations',
'5','Far Exceeds Expectations',
'Empty')
ELSE 'Empty'
END) as review_rating




My attempt to correct...


CASE WHEN YEAR(H.effdt) IN ('2001','2002') AND
(CASE H.review_rating
WHEN '1' THEN 'Exceeded Way, Exceeded Results'
WHEN '2' THEN 'Exceeded Way, Achieved Results'
WHEN '3' THEN 'Exceeded Way, Did not meet Results'
WHEN '4' THEN 'Achieved Way, Did not meet Results'
WHEN '5' THEN 'Achieved Way, Achieved Results'
WHEN '6' THEN 'Achieved Way, Exceeded Results'
WHEN '7' THEN 'Did not meet Way, Exceeded Results'
WHEN '8' THEN 'Did not meet Way, Achieved Results'
WHEN '9' THEN 'Did not meet Way, Did not meet Results'
ELSE 'Empty'
END)
OR
WHEN YEAR(H.effdt) IN ('2003','2004','2005') AND
(CASE H.review_rating
WHEN '1' THEN 'Does not Meet Expectations'
WHEN '2' THEN 'Partially Meets Expectations'
WHEN '3' THEN 'Meets Expectations'
WHEN '4' THEN 'Exceeds Expectations'
WHEN '5' THEN 'Far Exceeds Expectations'
ELSE 'Empty')
END)
END) AS review_rating




"Nicholas"
5280_Lifestyle
5280_Lifestyle
SSC Rookie
SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)SSC Rookie (40 reputation)

Group: General Forum Members
Points: 40 Visits: 325
Solved:


(CASE WHEN YEAR(H.effdt) IN ('2001', '2002') THEN
(CASE H.review_rating
WHEN '1' THEN 'Exceeded Way, Exceeded Results'
WHEN '2' THEN 'Exceeded Way, Achieved Results'
WHEN '3' THEN 'Exceeded Way, Did not meet Results'
WHEN '4' THEN 'Achieved Way, Did not meet Results'
WHEN '5' THEN 'Achieved Way, Achieved Results'
WHEN '6' THEN 'Achieved Way, Exceeded Results'
WHEN '7' THEN 'Did not meet Way, Exceeded Results'
WHEN '8' THEN 'Did not meet Way, Achieved Results'
WHEN '9' THEN 'Did not meet Way, Did not meet Results'
ELSE 'Empty'
END)
WHEN YEAR(H.effdt) IN ('2003','2004','2005') THEN
(CASE H.review_rating
WHEN '1' THEN 'Does not Meet Expectations'
WHEN '2' THEN 'Partially Meets Expectations'
WHEN '3' THEN 'Meets Expectations'
WHEN '4' THEN 'Exceeds Expectations'
WHEN '5' THEN 'Far Exceeds Expectations'
ELSE 'Empty'
END)
END) AS review_rating



"Nicholas"
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