1.利用 case when 实现多条件查询:
select *,
case when (select count(*) from PerformanceManagementForms where empno=empcode collate SQL_Latin1_General_CP1_CI_AS and Status like '%Finished')>0 then 'Finished' else
case when (select count(*) from PerformanceManagementForms where empno=empcode collate SQL_Latin1_General_CP1_CI_AS and Status like '%Manager Sign off222')>0 then 'Manager Sign off' else
case when (select count(*) from PerformanceManagementForms where empno=empcode collate SQL_Latin1_General_CP1_CI_AS and Status like '%Employee Sign off333')>0 then 'Employee Sign off'
else 'Not Started' end end end as Status from employee1 where empcode='991939'
2.利用case when 实现但条件查询:
select case Status when 'Finished' then '1' when 'Draft' then '2' else '3' end Status from employ
select *,
case when (select count(*) from PerformanceManagementForms where empno=empcode collate SQL_Latin1_General_CP1_CI_AS and Status like '%Finished')>0 then 'Finished' else
case when (select count(*) from PerformanceManagementForms where empno=empcode collate SQL_Latin1_General_CP1_CI_AS and Status like '%Manager Sign off222')>0 then 'Manager Sign off' else
case when (select count(*) from PerformanceManagementForms where empno=empcode collate SQL_Latin1_General_CP1_CI_AS and Status like '%Employee Sign off333')>0 then 'Employee Sign off'
else 'Not Started' end end end as Status from employee1 where empcode='991939'
2.利用case when 实现但条件查询:
select case Status when 'Finished' then '1' when 'Draft' then '2' else '3' end Status from employ
浙公网安备 33010602011771号