I have an SQL Server 2000 db, and I would like to retrieve summary information for all the numerical fields contained in the user tables of the database.
I can retrieve the names, datatypes and sizes with the following query:
SELECT t.name AS [TABLE Name],
c.name AS [COLUMN Name],
p.name AS [DATA Type],
p.length AS [SIZE]
FROM dbo.sysobjects AS t
JOIN dbo.syscolumns AS c
ON t.id=c.id
JOIN dbo.systypes AS p
ON c.xtype=p.xtype
WHERE t.xtype='U'
and p.prec is not null
How can I go one step further, and also list the average value contained within each field?
Can this be done with a subquery, or do I have to place the result of this query in a cursor and loop through a second select query for each column?