question

tlenzmeier avatar image
tlenzmeier asked

How to Get a List of Values From a Column in Every Table in a db?

Hello,

I'm trying to get a list of distinct values from a column that is in every table. Obviously, I could do them one at a time, but I'm hoping to create a SQL Agent job and put the results in a table.

Example

select distinct ClassID from dbo.Table1, Table2, and so on.

The output should have the name of the table and the distinct ClassID value. There are approximately 500 tables in the database. I've been asking Herr Google, but I can't seem to find what I'm looking for.

It should look some thing like this:

Table Name ClassID

Table 1 12345

sql-serversql querytables
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.