tsql - How do I use T-SQL's Case/When? -
i have huge query uses case/when often. have sql here, not work.
(select case when xyz.something = 1 'sometext' else (select case when xyz.somethingelse = 1) 'someothertext' end) (select case when xyz.somethingelseagain = 2) 'someothertextgoeshere' end) end) [columnname],
whats causing trouble xyz.somethingelseagain = 2
, says not bind expression. xyz alias table joined further down in query. whats wrong here? removing 1 of 2 case/whens corrects that, need both of them, more cases.
select case when xyz.something = 1 'sometext' when xyz.somethingelse = 1 'someothertext' when xyz.somethingelseagain = 2 'someothertextgoeshere' else 'something unknown' end columnname;
Comments
Post a Comment