我有一个大约20列的桌子.除了打字外:
Where column1 is null OR column2 is null OR column3 is null etc...
有更快的方法来检查每一列,看看是否有空值,如果是,返回该记录?
解决方法
没有.有办法更快地编码,但是没有像你这样的快捷方式.取自
an answer I gave on dba.stackexchange:
DECLARE @tb NVARCHAR(255),@sql NVARCHAR(MAX); SET @tb = N'dbo.[table]'; SET @sql = N'SELECT * FROM ' + @tb + ' WHERE 1 = 0'; SELECT @sql = @sql + N' OR ' + QUOTENAME(name) + ' IS NULL' FROM sys.columns WHERE [object_id] = OBJECT_ID(@tb); EXEC sp_executesql @sql;