Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
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
 
Old May 26th, 2006, 03:24 AM
Authorized User
 
Join Date: Nov 2005
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to joxa83 Send a message via Yahoo to joxa83
Default 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

 
Old May 26th, 2006, 08:04 AM
Friend of Wrox
 
Join Date: Dec 2005
Posts: 146
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
 
Old May 26th, 2006, 08:22 AM
Authorized User
 
Join Date: Nov 2005
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to joxa83 Send a message via Yahoo to joxa83
Default

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.

 
Old May 29th, 2006, 05:33 PM
Friend of Wrox
 
Join Date: Dec 2005
Posts: 146
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
 
Old May 30th, 2006, 03:58 AM
Authorized User
 
Join Date: Nov 2005
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to joxa83 Send a message via Yahoo to joxa83
Default

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

 
Old May 30th, 2006, 04:03 AM
Authorized User
 
Join Date: Nov 2005
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to joxa83 Send a message via Yahoo to joxa83
Default

Forgot to say I can not use front end app.

 
Old May 30th, 2006, 04:41 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i don't think there is a way because the two resultsets return different field layouts.

 
Old May 30th, 2006, 05:38 AM
Authorized User
 
Join Date: Nov 2005
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to joxa83 Send a message via Yahoo to joxa83
Default

yes sets have different shemas but there must be a way.

 
Old June 7th, 2006, 03:36 PM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old June 9th, 2006, 07:20 AM
Authorized User
 
Join Date: Nov 2005
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to joxa83 Send a message via Yahoo to joxa83
Default

Nice solution.Thank You.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Stored Procedure Help. midway11 SQL Language 3 November 20th, 2006 06:36 AM
Stored Procedure Help BukovanJ SQL Language 2 October 10th, 2006 08:02 AM
Chapter 12 - Multiple Active Result Sets mdrake BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 9 May 13th, 2006 06:33 AM
Stored Procedure rajanikrishna SQL Server 2000 0 July 18th, 2005 05:01 AM
Stored Procedure... babloo81 SQL Server 2000 2 May 1st, 2004 11:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.