Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Columns Differnt Values

Author  Topic 

GhantaBro
Posting Yak Master

215 Posts

Posted - 2008-04-01 : 17:19:17
How can we write a script that will provide me colmumns and all differnt set of values for those columns...

there are 300 plus columns all together.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-04-01 : 17:20:54
Could you provide a data example of what you mean?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

GhantaBro
Posting Yak Master

215 Posts

Posted - 2008-04-01 : 17:32:04
There are columns like Prefix, Suffix, Fec_1, dist, state, county, .... some_flag, code..
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-04-01 : 17:33:37
That doesn't make it more clear.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-04-01 : 17:35:24
If you need help from experts be clear in what you write?
Go to Top of Page

GhantaBro
Posting Yak Master

215 Posts

Posted - 2008-04-01 : 17:44:30
Say if we have a table with 300 columns and each column has set of values...

I need to find out what are distinct values in each columns?

Hope this makes sense..

thanks!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-04-01 : 17:51:07
Script the 300 queries like this:

SELECT 'SELECT DISTINCT ' + COLUMN_NAME + ' FROM ' + TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'YourTable' <--modify this

Then copy and paste into a new window and execute it.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

GhantaBro
Posting Yak Master

215 Posts

Posted - 2008-04-01 : 17:55:19
How can I put that in one report? There will 300 separate results rite using this?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-04-01 : 17:56:03
I have no idea how you are going to put this into a report. If you want to know the distinct values in each column, then you need 300 queries.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

GhantaBro
Posting Yak Master

215 Posts

Posted - 2008-04-01 : 17:59:22
I need to have something like :

age_ctgry
5
4
3
state
md
va
dc
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-04-01 : 18:07:25
You could union all of them together to get your desired output, but you are most likely going to run into data type issues.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

GhantaBro
Posting Yak Master

215 Posts

Posted - 2008-04-01 : 18:09:15
yeah plus there won't be any separator.
Go to Top of Page
   

- Advertisement -