I want to return a value into an alias fr开发者_Go百科om a case argument. I've tried various connotations around the following
CASE dbo.sch_group.group_code WHEN 'ERDS' THEN '1' AS alias_name
but I get incorrect syntax warnings near the alias
You're missing an END (CASE on MSDN). This is a "simple CASE expression"
CASE dbo.sch_group.group_code
WHEN 'ERDS' THEN '1'
END AS alias_name
If you have more conditions then it would be this
CASE dbo.sch_group.group_code
WHEN 'ERDS' THEN '1'
WHEN 'abcd' THEN '2'
ELSE <something>
END AS alias_name
I also assume this is in a SELECT or such
SELECT
col1, col2,
CASE dbo.sch_group.group_code
WHEN 'ERDS' THEN '1'
WHEN 'abcd' THEN '2'
ELSE <something>
END AS alias_name
FROM
dbo.sch_group
WHERE
...
This is from ORACLE so I'm not sure if it'll work in SQL Server but:
(CASE WHEN dbo.sch_group.group_code = 'ERDS' THEN '1' END) AS alias_name
精彩评论