select PERSONNUM, PAYCODENAME as StraightTime, PAYCODENAME as OT
from dbo.VP_ALLTOTALS
where OT in ('Overtime', 'Double Overtime')
return 'OT',
and StraightTime in ('Straight Time Earnings', 'Sunday Premium')
return 'Straight Time'
问问题
103 次
2 回答
0
Where 子句仅是过滤器...使用 case 语句将逻辑放入选择行。
select PERSONNUM, PAYCODENAME as StraightTime, PAYCODENAME as OT
case when OT in ('Overtime', 'Double Overtime') then 'OT',
when StraightTime in ('Straight Time Earnings', 'Sunday Premium') then 'Straight Time'
else 'not in list?' end as 'returnedcode' --name your new column here
from dbo.VP_ALLTOTALS
于 2013-09-20T21:33:35.873 回答
0
我假设您正在寻找 CASE
:
SELECT CASE
WHEN ot IN ( 'Overtime', 'Double Overtime' ) THEN ot
WHEN straighttime IN ( 'Straight Time Earnings', 'Sunday Premium' )
THEN straighttime
ELSE NULL
END AS ColumnName
FROM dbo.vp_alltotals
或者,如果您只想返回字符串OR
/ Straight Time
:
SELECT CASE
WHEN ot IN ( 'Overtime', 'Double Overtime' ) THEN 'OT'
WHEN straighttime IN ( 'Straight Time Earnings', 'Sunday Premium' )
THEN 'straighttime'
ELSE NULL
END AS Type
FROM dbo.vp_alltotals
于 2013-09-20T21:34:10.393 回答