Is there any way in Sql Server Management Studio (2008) whereby I can view the data types of each field in the result of a query?
In this case, I am running a stored procedure which returns a result set, and I would like to know the lengths of the nvarchar columns and precision of decimals.
In the past, I have created a view which contains the underlying query in the stored procedure, and then viewed the column list, but the query within the procedure is much too complex to do so in this case.
Any ideas?
You can get a list of the schemas using an SSMS or T-SQL query. To do this in SSMS, you would connect to the SQL instance, expand the SQL database and view the schemas under the security folder. Alternatively, you could use the sys. schemas to get a list of database schemas and their respective owners.
To show the schema, we can use the DESC command. This gives the description about the table structure.
Using Shortcut Keys If we just use Ctrl+R we can toggle between showing and hiding the results pane and therefore you can see more of the Editor section when you are using SQL Server Management Studio.
Quick and dirty snippet, requires all the fields in the result set are named or aliased;
select * into #T
from
openrowset('SQLNCLI', 'Server=.;Trusted_Connection=yes;', 'exec thedb.dbo.sp_whatever')
exec('use tempdb exec sp_columns #T drop table #T')
Your best bet may be to use OPENROWSET to store the output of the procedure into a table, then examine that table. Something like:
SELECT * INTO YourHoldingTable
FROM OPENROWSET('SQLNCLI', 'Server=YourServerName;Trusted_Connection=yes;', 'EXEC YourDatabase.YourSchema.YourProcedureName')
GO
sp_help 'YourHoldingTable'
GO
DROP TABLE 'YourHoldingTable'
GO
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With