Avatar of Junior Vasquez
Junior Vasquez
Flag for El Salvador

asked on 

Getting Column Count and value from Table name in schema

I've tried to ask this before, but maybe I was going about it in the wrong way.

If if have this query

select  
        s.[name]            'Schema',
        t.[name]            'Table',
        c.[name]            'Column',
        d.[name]            'Data Type'
from        sys.schemas s
inner join  sys.tables  t
on s.schema_id = t.schema_id
inner join  sys.columns c
on t.object_id = c.object_id
inner join  sys.types   d
on c.user_type_id = d.user_type_id
where s.name <> 'History'
and t.name not like 'CV%'
and t.name <> 'ServiceLog'
and t.name <> 'sysdiagrams'

Open in new window


that will get me the table names....

Then next part I need, is a loop that will go thru each table, then go and get every column name associated with that table. It will get the count of each column for each value..... including blanks and nulls.

I'm assuming that a cursor is needed, bt i'm looking for a better way than doing this for each table, as it needs to be automated.
Microsoft SQL ServerSQL

Avatar of undefined
Last Comment
Junior Vasquez

8/22/2022 - Mon