Query column nullability of the resulting rowset of a tsql SELECT statement?
Consider the following pseudo-tsql
table a
{
field1 int,
field2 int NULL
}
table b
{
field1 int,
field3 int
}
create procedure Sp1
As
Select a.field1, a.field2, b.field3
From a inner join b on a.field1 = b.field1
Is it possible to query the procedure Sp1 for if the resulting columns can be null or not? It seems the dataset generator can pull that off right?
Can it be done in tsql? By o开发者_JAVA百科ther means?
Desired output:
field1 int, field2 int NULL, field3 int
Or:
field1, field2 nullable, field3
(The first would obviously be better)
Thanks!
The dataset generator will set the FMTONLY set option on. This causes empty result sets to be returned to the client, instead of actually running the queries. Most client data access technologies (e.g. ADO.Net, SQL Native client, etc) have ways of interrogating result set objects (even empty ones) and determining schema information about them.
I can't think of a way to actually consume this information from T-SQL though. The only way of grabbing a result set from a stored procedure is INSERT...EXEC, but in that case, you have to already have a table defined.
精彩评论