Tuesday, 21 January 2014

Get Return Types of a SQL Server Query

Sp_help gives details about table columns. Combining this with a view can return types of query results.

Syntax for sp_help command
  exec sp_help 
Creating a view from a select query
  CREATE VIEW QueryResults AS
  SELECT * FROM SomeTable
Run sp_help to find details of return types
exec sp_help QueryResults
You can do all 3 steps in one go, but you will need the go command after creating a view
-- create view with select query
CREATE VIEW QueryResult AS
SELECT TOP 1  * FROM Items
GO

-- get details of result like type info
exec sp_help QueryResult

-- drop view since we are done with it
DROP VIEW QueryResult
In sql server management studio the output will look something like this:

No comments:

Post a Comment