Reputation: 1
I am pretty familiar with the COUNT function in SQL, but I don't know how to use it to achieve the results I'm looking for.
I manage a data warehouse with routine loads and I would like to report the number of raw data points (defined by #records * #columns) each time I load records into a table.
I can use the COUNT function to get the #records in the formula, but how can I dynamically count columns in a table? From there I can do the math.
Thanks!
Upvotes: 0
Views: 965
Reputation: 15185
You can query the schema tables where table meta data is stored in sql server.
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'MyTable'
SELECT COUNT(*) FROM MyTable
Upvotes: 1