SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Counting values in table columns
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

dzabor
Posting Yak Master

USA
132 Posts

Posted - 02/01/2013 :  16:21:01  Show Profile  Send dzabor an AOL message  Reply with Quote
I have a table with numerous columns, many of which are most likely not being used since moving from schema to schema and business practice to business practice over the years. I need to count the populated fields within the table to determine if we keep it or not moving forward.

ID, Demographic1,Demographic2,Demographic3,Demographic4,Demographic5

I need it to return the following:

ID, Demographic1,Demographic2,Demographic3,Demographic4,Demographic5
254 , 17 , 13, 0, 5, 200

James K
Flowing Fount of Yak Knowledge

3569 Posts

Posted - 02/01/2013 :  17:23:17  Show Profile  Reply with Quote
If the non-populated values are NULL, you can do this:
SELECT
	COUNT(ID),
	COUNT(Demographic1),
	COUNT(Demographic2),
	COUNT(Demographic3),
	COUNT(Demographic4),
	COUNT(Demographic5)
FROM
	TheTable
Go to Top of Page

dzabor
Posting Yak Master

USA
132 Posts

Posted - 02/01/2013 :  20:25:03  Show Profile  Send dzabor an AOL message  Reply with Quote
Thanks!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000