Get data types from arbitrary sql statement in SQL Server 2008

Posted by Christopherous 5000 on Stack Overflow See other posts from Stack Overflow or by Christopherous 5000
Published on 2010-04-01T18:03:33Z Indexed on 2010/04/01 18:13 UTC
Read the original article Hit count: 265

Filed under:
|
|
|

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...

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server-2008