January 8, 2014 at 10:15 am
I am trying to use CAST in a case statement with two clauses but am stuck up with the syntax.
Can anyone advise.
CAST(Case when W.Employee_Type like '%CX5000%' and
W.Employee_Policy AS VARCHAR(10)) = 'Yes' then 1 else 0 end as Count1
January 8, 2014 at 10:29 am
You have a problem with your nesting. You're opening your cast before the case and closing it in the middle of the case. It has to be either all out or all in.
This might be closer to what you need.
Case when CAST(W.Employee_Type AS VARCHAR(10)) like '%CX5000%' and
CAST(W.Employee_Policy AS VARCHAR(10)) = 'Yes' then 1 else 0 end as Count1
January 8, 2014 at 10:33 am
Thank you. Got it working...
SELECTCAST(
CASE WHEN someCondition THEN someValue
ELSE otherValue
END
as CHAR(11)
)
FROMtableExpression
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply