﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Discuss Content Posted by Leo Peysakhovich / Article Discussions / Article Discussions by Author  / Exotic SQL: NULL Column Analysis / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sat, 25 May 2013 10:16:44 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Exotic SQL: NULL Column Analysis</title><link>http://www.sqlservercentral.com/Forums/Topic126693-163-1.aspx</link><description>Hi - This really helped me field a query from my boss ultra quick - I appreciate your hard work being shared.</description><pubDate>Tue, 13 Dec 2011 08:06:39 GMT</pubDate><dc:creator>russella0-96423</dc:creator></item><item><title>RE: Exotic SQL: NULL Column Analysis</title><link>http://www.sqlservercentral.com/Forums/Topic126693-163-1.aspx</link><description>&lt;P&gt;Great article. I found that blew up when the table owner was not the dbo so I added a little bit of code and it worked beautifully. Thanks for sharing. Here is the modified version:&lt;/P&gt;&lt;P&gt;Use pubs&lt;/P&gt;&lt;P&gt;drop table pubs..tmp_countgoCreate table pubs..tmp_count(dbnm varchar(50), owner varchar(255), tbl varchar(255), col varchar(255), nulls int, tot int)go&lt;/P&gt;&lt;P&gt;------------------------------------------------------------------------------------ begin batch----------------------------------------------------------------------------------BEGINdeclare @sql Nvarchar(1000), @minid int, @maxid int,@table_n varchar(255), @col varchar(255), @dbnm varchar(50), @ownernm varchar(50)declare @tmp1 table (idint identity(1,1), tbl varchar(255), col varchar(255), owner varchar(255))&lt;/P&gt;&lt;P&gt;set @dbnm = db_name()truncate table pubs..tmp_countinsert into @tmp1(tbl,col,owner)select so.name, sc.name, su.name from syscolumns scinner join sysobjects so on so.id = sc.idinner join sysusers su on so.uid = su.uidwhere so.name not like 'ERR_%' and so.type = 'U' andsc.isnullable = 1select @minid = 1, @maxid = max(id) from @tmp1while (@minid &amp;lt;&lt;A href="mailto:=@maxid"&gt;=@maxid&lt;/A&gt;) begin select @table_n = tbl,@col = col,@ownernm = owner from @tmp1 where id = @minid select @sql = ' insert into pubs..tmp_count(dbnm, owner, tbl, col , nulls , tot)' select @sql = @sql + ' select ''' + @dbnm + ''', ''' + @ownernm + ''', ''' + @table_n + ''', ''' +  @col + ''', (select count(*) from [' + @ownernm + '].[' + @table_n + '] where ['+ @col + '] is null) ' select @sql = @sql + ' , (select count(*) from [' + @ownernm + '].[' + @table_n +'])'&lt;/P&gt;&lt;P&gt; exec ( @sql ) set @minid = @minid + 1 endEND------------------------------------------------------------------------------------- end batch-----------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;select left(dbnm,10) as dbnm, left(owner,20) as owner, left(tbl,20) as tbl, left(col,20) as col,tot, nulls, tot - nulls as NotNulls from pubs..tmp_count order by NotNulls&lt;/P&gt;</description><pubDate>Tue, 09 Nov 2004 08:35:00 GMT</pubDate><dc:creator>Richard Nadeau</dc:creator></item><item><title>Exotic SQL: NULL Column Analysis</title><link>http://www.sqlservercentral.com/Forums/Topic126693-163-1.aspx</link><description>Comments posted to this topic are about the content posted at &lt;A HREF=http://www.sqlservercentral.com/columnists/lPeysakhovich/exoticsqlnullcolumnanalysis.asp&gt;http://www.sqlservercentral.com/columnist</description><pubDate>Fri, 16 Jul 2004 09:38:00 GMT</pubDate><dc:creator>Leo Peysakhovich</dc:creator></item></channel></rss>