Using WITH RESULT SETS to redefine column names and data types of stored procedure’s result set
Using WITH RESULT SETS option, we can redefine the metadata of result set(s) of a stored procedure during execution. We can use the below code to change the column names and data types of result sets(s) of stored procedure without making any change in the existing code:
1
2
3
4
5
6
7
8
9
10
11
12
13
| EXEC [dbo].[uspGetEmployeeManagers] @BusinessEntityID = 101 WITH RESULT SETS ( ( ReportingLevel INT , BusinessEntityID INT , FirstName NVARCHAR(50), LastName NVARCHAR(50), OrganizationNode NVARCHAR( MAX ), ManagerName NVARCHAR(50) ) ) |
Here is the output of the stored procedure after redefining the column definitions using WITH RESULT SETS option:
ReportingLevel BusinessEntityID FirstName LastName OrganizationNode ManagerName
ReportingLevel BusinessEntityID FirstName LastName OrganizationNode ManagerName
Below is the syntax to define column names and data types in case we need to handle multiple result sets:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| EXEC ProcedureName @Param = 'Value' WITH RESULT SETS ( --Result set 1 ( Column1 DataType, Column2 DataType, Column3 DataType --Define all columns ), --Result set 2 ( Column1 DataType, Column2 DataType, Column3 DataType --Define all columns ), --Result set 3 ( Column1 DataType, Column2 DataType, Column3 DataType --Define all columns ) --And so on ) |
WITH RESULT SETS option – Limitations
- We cannot redefine a subset of columns – Either all columns of a result set need to be defined or none of them can be defined using WITH RESULT SETS option.
- Cannot redefine a subset of result sets – In case the stored procedure return multiple result sets, either all result sets (with all columns) need to be defined or none of them can be defined.
- Cannot change the order of the columns and result sets – We cannot change the sequence of columns and result sets.
- Cannot use calculation or type casting – We cannot use calculations or type casting with the columns.
Such a nice blog, keep sharing with us, if you want to
ReplyDeletebuy cushion covers online india then let us know at +91–9650270867
Nice blog, keep writing like this
ReplyDeleteI must recommend your blog, that is such a nice blog and if you want to buy Fridge Cover then click on the link.
Nice blog, keep writing like this
ReplyDeleteFind here online price details of companies selling Mattress Cover Cotton. Get info of suppliers, manufacturers, exporters, traders of Mattress Cover Near Me for buying in India.
Nice blog, keep writing like this
ReplyDeleteBuy Washing Machine Cover at low prices in India. Select from range of home improvement tools & Washing Machine Cover of all brands from Dreamcareindia.com
Washing Machine Cover
Washing Machine Cover Price
Washing Machine Cover Online
Washing Machine Cover Manufacturers
Washing Machine Cover Waterproof
Washing Machine Cover Near Me
Cover for Washing Machine
Washing Machine Cover IFB
Washing Machine Cover LG
Washing Machine Cover Whirlpool
Nice blog, keep writing like this
ReplyDeleteBuy Milwaukee at low prices in UK. Select from range of home improvement tools & Milwaukee UK of all brands from tools4trade.co.uk
Milwaukee
Milwaukee UK
Milwaukee Power Tools
Milwaukee Fuel
Milwaukee UK Cordless
Corded Power Tools
Milwaukee power tools UK
ReplyDeleteNice Your Blog
Visit My Blogs:-
Fridge Cover
Fridge Protector
Ffreeze Cover
Fridge Mats
Table Cover
Table Cover Online
Table Cover Design
Table Cover Plastic
Table Cover Price
Table Cover Price
Center Table Cover
Centre Table Cover
Dining Table Cover
Table Mats
Table Placemat