我需要类似的东西
SELECT * FROM table AS t WHERE ANY(t.* IS NULL)
我不想这样做
SELECT * FROM table AS t WHERE t.c1 = NULL OR t.c2 = NULL OR t.c3 = NULL
这将是一个巨大的查询.
DECLARE @tb NVARCHAR(255) = N'dbo.[table]'; DECLARE @sql NVARCHAR(MAX) = N'SELECT * FROM ' + @tb + ' WHERE 1 = 0'; SELECT @sql += N' OR ' + QUOTENAME(name) + ' IS NULL' FROM sys.columns WHERE [object_id] = OBJECT_ID(@tb); EXEC sp_executesql @sql;