I would like to execute the following command to retrieve the top values on all the fields of my database:
select top(100) COLUMN_NAME, count(*) as number
from DATABASE_TABLE
group by COLUMN_NAME
ORDER BY number DESC
That is, iterate through all the database tables, and all fields and calculate the top values.
How can I do this using a stored procedure or SQL query? I know how to get all the fields of the database:
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
but I don't know how to plug this into a stored procedure.
Any help would be appreciated.