选择除仅具有空值的那些列以外的所有列

选择除仅具有空值的那些列以外的所有列,第1张

选择除仅具有空值的那些列以外的所有列

创建具有以下内容的存储过程:

create table #cols (colname varchar(255), nullCount int)insert into #cols (colname)select name from syscolumns where id = object_id('tblTest')declare @c varchar(255)declare curCols cursor for select colname from #colsopen curColsfetch next from curCols into @cwhile @@fetch_status = 0 begin  exec ('update #cols set nullCount = (select count(*) from tblTest where ' + @c + ' is not null) where colname = ''' + @c + '''')  fetch next from curCols into @cendclose curColsdeallocate curColsdeclare @rv table (cols_expect_those_with_null_only varchar(255))insert into @rv (cols_expect_those_with_null_only)select colname from #colswhere nullCount > 0drop table #colsselect * from @rv


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5508867.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-13
下一篇 2022-12-13

发表评论

登录后才能评论

评论列表(0条)

保存