答案 0 :(得分:5)
答案 1 :(得分:0)
听起来我正在尝试为指定的用户(行)找到一个空列。并且,空列包含NULL。假设这是正确的并忽略了对正确设计的担忧,这里将返回包含NULL值的第一列的数字。
SELECT CASE
WHEN I0 IS NULL THEN 0
WHEN I1 IS NULL THEN 1
WHEN I2 IS NULL THEN 2
WHEN I3 IS NULL THEN 3
WHEN I4 IS NULL THEN 4
WHEN I5 IS NULL THEN 5
WHEN I6 IS NULL THEN 6
WHEN I7 IS NULL THEN 7
WHEN I8 IS NULL THEN 8
WHEN I9 IS NULL THEN 9
END AS NextColumn
FROM MyTable
WHERE UserID = 'Me'
;
答案 2 :(得分:0)
SELECT COALESCE(I0, I1, I2, I3, I4, I5, I6, I7, I8, I9) AS FirstNotNull
FROM MyTable