我试图返回一个'1'或'0',而不是两者都是Case语句中出现的当前情况。我目前的陈述如下。如果名字下面有任何O,那么我需要显示而不是'1'。如果没有'0'那么我想要'1'来表示。谢谢你的帮助。
SELECT Distinct Room,
Unit,
Number,
(LastN +', '+ FirstN) AS Name,
min( CASE WHEN Ques1_Yes = '0' THEN '0'
WHEN Ques2_Yes = '0' THEN '0'
WHEN Ques3_Yes = '0' THEN '0'
WHEN Ques4_Yes = '0' THEN '0'
WHEN Ques6_Yes = '1' THEN '0'
WHEN Name IS NULL THEN '-1'
ELSE '1'
END AS Direction
FROM Customer_Service.dbo.Name
WHERE Name = 'smiff, jess'
现在我想知道如何让它发挥作用。对不起,我比sql更新
答案 0 :(得分:0)
也许是这样的?
SELECT
min( CASE WHEN Ques1_Yes = '0' THEN '0'
WHEN Ques2_Yes = '0' THEN '0'
WHEN Ques3_Yes = '0' THEN '0'
WHEN Ques4_Yes = '0' THEN '0'
WHEN Ques6_Yes = '1' THEN '0'
WHEN Name IS NULL THEN 'NULL'
ELSE '1'
END) AS Direction
FROM Customer_Service.dbo.Name
WHERE Name = 'smiff, jess'