表格结构:
Customer
ID int not null,
Name varchar(100) null
查询:
SELECT ID,
(SELECT CASE WHEN (Name IS NULL AND Name <> '')
THEN CAST(1 AS BIT)
ELSE CAST(0 AS BIT) END
FROM Customer) AS IsNameNullOrWhitespace
这给了我'子查询返回超过1的值这是..'。这是为什么?
答案 0 :(得分:2)
您似乎不需要子查询 - 您可以将case
嵌入到顶级select
中,如下所示:
SELECT id,
CASE
WHEN ( name IS NULL
AND name <> '' ) THEN Cast(1 AS BIT)
ELSE Cast(0 AS BIT)
END AS IsNameNullOrWhitespace
FROM customer
答案 1 :(得分:1)
SELECT ID,
Case When IsNull(Name,'') ='' Then CAST(1 AS BIT) Else CAST(0 AS BIT) End
IsNameNullOrWhitespace
FROM Customer
您需要以上查询。