Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
bsethi24
Starting Member
25 Posts |
Posted - 2012-06-22 : 10:25:10
|
Dear All,Hi I have a Store Procedure which gives OUTPUT in 2 Data Sets (Tables). Now I need to store both data sets output in a table or in 2 different tables.How can I achieve this in MS-SQL Server ? Please guide.Example: -EXEC Pr_Class_School_Dtl @Class = 1Then Output is coming in 2 Data Sets (Tables): -Data Set (Table) 1: -Label Q1 Q2 Q3 Q4 Q5Class I A B C D EData Set (Table) 2: -Schools BoardOutlook CBSEMS RGPVMac TestIf we have only one Data Set(Table) then we can do this as below. But, how can we output of Store Procedures which returns multiple data sets (tables).Insert Into #tt (Label, Q1, Q2, Q3, Q4, Q5) EXEC Pr_Class_Question_Dtl @Class = 1But, how can we do this for Multiple Data Sets(Tables) in MS-SQL Server ? Please guide.Thanks & Regards, |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-06-22 : 10:42:10
|
quote: Originally posted by bsethi24 Dear All,Hi I have a Store Procedure which gives OUTPUT in 2 Data Sets (Tables). Now I need to store both data sets output in a table or in 2 different tables.How can I achieve this in MS-SQL Server ? Please guide.Example: -EXEC Pr_Class_School_Dtl @Class = 1Then Output is coming in 2 Data Sets (Tables): -Data Set (Table) 1: -Label Q1 Q2 Q3 Q4 Q5Class I A B C D EData Set (Table) 2: -Schools BoardOutlook CBSEMS RGPVMac TestIf we have only one Data Set(Table) then we can do this as below. But, how can we output of Store Procedures which returns multiple data sets (tables).Insert Into #tt (Label, Q1, Q2, Q3, Q4, Q5) EXEC Pr_Class_Question_Dtl @Class = 1But, how can we do this for Multiple Data Sets(Tables) in MS-SQL Server ? Please guide.Thanks & Regards,
As far as I know, this is not possible.The insert..exec simply tries to dump all the data into the table. If both of your datasets had exactly same number of columns and data types, then it would insert the results of both datasets into a the table. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-06-22 : 23:12:11
|
i would have done this using two separate procedures. It doesnt make sense for same procedure to return varying type of resultsets.that being said, if your situations demands it due to some constraints, i would still make both resultsets same by putting place holders for all columns using NULL values whenever a particular column is not included in resultset and have an additional column to indicate category. this can later be used to filter out individual records from table.so something likeEXEC Pr_Class_School_Dtl @Class = 1Then Output is coming in 2 Data Sets (Tables): -Data Set (Table) 1: -Label Q1 Q2 Q3 Q4 Q5 Schools Board CategoryClass I A B C D E NULL NULL Resultset1Data Set (Table) 2: -Label Q1 Q2 Q3 Q4 Q5 Schools Board CategoryNULL NULL NULL NULL NULL NULL Outlook CBSE Resultset2NULL NULL NULL NULL NULL NULL MS RGPV Resultset2NULL NULL NULL NULL NULL NULL Mac Test Resultset2Insert Into #tt (Label Q1 Q2 Q3 Q4 Q5 Schools Board Category) EXEC Pr_Class_Question_Dtl @Class = 1...then for getting individual resultsetSELECT Label, Q1, Q2, Q3, Q4, Q5FROM #tt WHERE Category = 'Resultset1'SELECT Schools, BoardFROM #tt WHERE Category = 'Resultset2'[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|