 |
| SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

May 26th, 2006, 03:24 AM
|
|
Authorized User
|
|
Join Date: Nov 2005
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
stored procedure with two result sets
Is there possible two fill table with second result set returned by stored proc.For instance
create proc test
as
begin
select *from orders
select *from Employees
end
insert into sometable exec test
So I want to fill table 'sometable' with result set
'select *from Employees'. There by tables 'sometable' and 'Employees' have same shema
|
|

May 26th, 2006, 08:04 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2005
Posts: 146
Thanks: 0
Thanked 1 Time in 1 Post
|
|
CREATE TABLE #FileList (Files varchar(8000))
INSERT #FileList (Files)
EXEC master.dbo.xp_cmdshell 'dir c:\'
David Lundell
Principal Consultant and Trainer
www.mutuallybeneficial.com
|
|

May 26th, 2006, 08:22 AM
|
|
Authorized User
|
|
Join Date: Nov 2005
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I don't understand. You called proc to fill table.That is ok but as I said I have one procedure wich I can not change, then that proc returns two sets, then I need second set for some calculations in my proc, then I need data from exactly that procedure wich returns two sets.
|
|

May 29th, 2006, 05:33 PM
|
|
Friend of Wrox
|
|
Join Date: Dec 2005
Posts: 146
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Sorry joxa83 -- I must have misunderstood the problem. You could call it from a client app, get the second result set and then insert that data into a table.
David Lundell
Principal Consultant and Trainer
www.mutuallybeneficial.com
|
|

May 30th, 2006, 03:58 AM
|
|
Authorized User
|
|
Join Date: Nov 2005
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
That is the problem I have one procedure wich I can not change, then that proc returns two set, then I need second set for some calculations in my proc, then I need data from exactly that procedure wich returns two sets
|
|

May 30th, 2006, 04:03 AM
|
|
Authorized User
|
|
Join Date: Nov 2005
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Forgot to say I can not use front end app.
|
|

May 30th, 2006, 04:41 AM
|
|
Friend of Wrox
|
|
Join Date: May 2006
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i don't think there is a way because the two resultsets return different field layouts.
|
|

May 30th, 2006, 05:38 AM
|
|
Authorized User
|
|
Join Date: Nov 2005
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
yes sets have different shemas but there must be a way.
|
|

June 7th, 2006, 03:36 PM
|
|
Friend of Wrox
|
|
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I am not sure why you would want to combine the two. But I recall I once came up with an obscure need for this. I created a column called RS for result set. Set the value to one for the first result set, to two for the second. added the two result sets together increasing the columns. For example say I do the following two selects.
Select firstname, lastname from x
Select city, state from y
the result set would come out like this.....
rs FirstName LastName City State
1 John doe
1 Susan Smith
1 Pewee Herman
1 Dubya Bush
2 Hollywood CA
2 New York NY
2 Oklahoma City OK
2 Seattle WA
Notice for RS = 1 there are not city or state values, and for RS = 2
there are no names.
You can do this with a temp table probably easiest.
Hope this helps,
Rob
|
|

June 9th, 2006, 07:20 AM
|
|
Authorized User
|
|
Join Date: Nov 2005
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Nice solution.Thank You.
|
|
 |