根據表名自動循環查找某列的值特徵【本實例查找null值】

declare @table_name as varchar(max)
set @table_name = 'C0t01'
declare @column_Value varchar(200)
declare aaaaa cursor for
select sys.columns.name
  from sys.columns, sys.tables, sys.types where sys.columns.object_id = sys.tables.object_id and sys.columns.system_type_id=sys.types.system_type_id and sys.tables.name=@table_name order by sys.columns.column_id
open  aaaaa
fetch next from aaaaa  into @column_Value
while @@fetch_status=0
  begin


     declare @strsql varchar(200)
     set @strsql='select * from '+@table_name+' where '+@column_Value+' is null'
     execute(@strsql)
     if @@rowcount>0
       begin
           print '列'+@column_Value+'有空值'
       end
     ELSE
     fetch next from aaaaa  into @column_Value
  end
close aaaaa
deallocate aaaaa

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章