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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Access to stored procedure data

Author  Topic 

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2007-11-22 : 04:47:10
Hi i've a stored procuedure that gives me a result set for products, i want to join up the supplier table to this result set to get the distinct list of suppliers, i know the 2 columns to join up on, What i don't know is how to access the result set of the stored procudure. to join up both tables,

I think i can use openrowset would i be on the right path ?

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2007-11-22 : 08:17:57
No, the only way you can do this is inserting the result set of the procedure into a table.

see http://www.sqlteam.com/article/stored-procedures-returning-data
Go to Top of Page

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2007-11-22 : 09:41:00
Thanks for the link, what i can't see on it, is if i just want to use 2 columns out of the result set from the stored procedure.

What i've done so far is.

Create a temp table
inert into into my temp table
call to stored procedure

insert into #temp_tbl(supplier_c,product_c)
exec sp_prod

Can i pick what columsn i require out of the stored procedure result set ?

Go to Top of Page

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2007-11-22 : 21:56:19
Picking a column from a result set in the stored procedure? Sorry but I don't think so. But you can use a UDF that will return a result set, and from that UDF result set you can used a where clause to meet your needs.

Sample...


CREATE FUNCTION dbo.fnCompanyLedger(
@From as datetime
,@To as datetime
,@CompanyID as numeric(18,0)
) RETURNS @List TABLE
(
Id int identity(1,1),
col1 varchar(200),
col2 varchar(200),
col3 varchar(200),
col4 varchar(200),
col5 varchar(200),
col6 varchar(200),
trans7 varchar(200),
trans8 varchar(200),
trans9 varchar(200),
trans10 varchar(200),
trans11 varchar(200),
trans12 varchar(200),
trans13 varchar(200),
trans14 varchar(200),
transID as numeric(18),
CompanyID as numeric(18)
)

BEGIN

insert into @List (col1, col2, col3, col4, col5, col16,
trans7, trans8, trans9, trans10,
trans11, trans12, trans13, trans14, transID, CompanyID)
select t1.col1
,t2.col2
,t3.col2
,t4.col2
,t5.col2
,t6.col2
,t.trans7, t.trans8, t.trans9, t.trans10,
,t.trans11, t.trans12, t.trans13, t.trans14, transID, t.CompanyID
from tbltransactions as t
left join tbl1 as t1 on t1.id = t.id
left join tbl2 as t2 on t2.id = t1.id
left join tbl3 as t3 on t3.id = t1.id
left join tbl4 as t4 on t4.id = t.id
left join tbl5 as t5 on t5.id = t.id
left join tbl6 as t6 on t6.id = t.id
WHERE dtFrom >= @From and dtTo <= @To
and CompanyID = @CompanyID
RETURN

END


Sample used...

select tbl.col1
from dbo.fnCompanyLedger('11/20/2007','11/22/2007') as tbl
where tbl.transID = 234




For fast result follow this...
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

Want Philippines to become 1st World COuntry? Go for World War 3...
Go to Top of Page

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2007-11-23 : 07:12:43
Thanks for your help on this. what i had to do was to create a temp table to hold all the columns of the stored procedure result set and then join the temp table to my other table, this in turn gave me another stored procedure result set, which i did not want as i rather get the result of the 2nd stored procedure to a table.
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2007-11-23 : 07:32:26
I think you may be misunderstanding result sets here, if you ran:

insert into #temp_tbl(supplier_c,product_c)
exec sp_prod


then if you wanted just 2 columns from this you simply just select those two columns:

select col1,col2 from #temp_tbl


Please post what you were doing and what you expect as a result.
Go to Top of Page

rookie_sql
Constraint Violating Yak Guru

443 Posts

Posted - 2007-11-26 : 06:04:42
Hi RickD,

I think you already answered my question but i explain what am after again, i have a stored procedure, that when i execute it gives me a result set, of 10 columns. i only want 2 of the columns, so what i asked was it possible to create a temp table with 2 columns and then call the stored procedure and just insert the 2 columns i need from the stored procedure into the temp table. I don't think this is possible ??.

What i did was create a temp table to hold all the columsn from the results set of the stored procedure.
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2007-11-26 : 12:38:23
No, it is not possible, you can only fill the temp table with the resultset of the SP. Unless you change the SP, then all you can do is put the all the columns in your table and then just selecrt the two columns you want from that table.
Go to Top of Page
   

- Advertisement -