Search code examples
sql-serverssms

How to determine the datatypes of the results of a SQL?


We have a SQL query that pulls a large number of fields from many tables/views from a database. We need to put a spec together for integration with a 3rd party, what is the quickest way to compile the data types of the result set?

Clarifications:

  • There are 25+ tables/views involved, so functions at the table level will still be cumbersome.
  • All work is currently being done in Microsoft SQL Server Management Studio.

Solution

  • You can run the query with SET FMTONLY ON, but that might not help you to easily determine the data types returned, since you're working in management studio only. If it was me, I think I'd create a view temporarily with the same body as the stored procedure (you may have to declare variables for any parameters). You can then look at the columns returned by the view with the INFORMATION_SCHEMA queries already discussed.