我正试图用下面的语句在case语句的else部分设置多个值。
Create TABLE Student(
id int NOT NULL,
Fname VARCHAR(25),
Lname VARCHAR(25),
AbsentDate VARCHAR(50),
AbsenceReason VARCHAR(100)
);
Insert INTO Student(id,Fname,Lname,AbsentDate,AbsenceReason)
values(001,'Jack','P','01-10-2020','Fever'),
(002,'Jack','L',NULL,NULL);
select
CASE WHEN s.AbsentDate IS NOT NULL THEN 'Y' Else 'N' As StudentAbsence(Y/N),AbsenceReason='' END
from Student s`
Expected Result
id,Fname,Lname,AbsentDate,AbsenceReason
001,'Jack','P','01-10-2020','Fever'
002,'Jack','L',NULL,Blank --update Null to Blank
有可能做到这一点吗?
SELECT
id,
Fname,
Lname,
CASE WHEN AbsentDate IS NULL THEN 'N' ELSE 'Y' END AS [StudentAbsence(Y/N)],
AbsentDate AS AbsenceDate,
CASE WHEN AbsentDate IS NULL THEN '' ELSE AbsenceReason END AS AbsenceReason
FROM
Student
小提琴