Get data types from arbitrary sql statement in SQL Server 2008
- by Christopherous 5000
Given some arbitrary SQL I would like to get the data types of the returned columns. The statement might join many tables, views, TVFs, etc. I know I could create a view based on the query and get the datatypes from that, hoping there's a quicker way. Only think I've been able to think of is writing a .net utility to run the SQL and examine the results, wondering if there is a TSQL answer.
i.e.
Given (not real tables just an example)
SELECT p.Name AS PersonName, p.Age, a.Account as AccountName
FROM Person as p
LEFT JOIN Account as a
ON p.Id = a.OwnerId
I would like to have something like
PersonName: (nvarchar(255), not null)
Age: (smallInt, not null)
etc...