Showing posts with label tblcustomer. Show all posts
Showing posts with label tblcustomer. Show all posts

Wednesday, March 7, 2012

join table with procedure?

Is it possible to join the results of a stored procedure with a table?
SELECT field1, field2, field3 FROM tblCustomer INNER JOIN (exec spTest
'inputvar' AS SP) ON tblCustomer.CustID = SP.CustID
Thanks,
KeithKeith G Hicks,
You need to grab the result of the sp into a table (permanent or temporal)
and use the table in the join, or you can re-write the sp as a table functio
n.
create table #t1(c1 ...)
insert into #t1(c1, ...)
exec spTest 'inputvar'
SELECT field1, field2, field3
FROM tblCustomer INNER JOIN #t1 AS SP ON tblCustomer.CustID = SP.CustID
drop table #t1
go
How to share data between stored procedures
http://www.sommarskog.se/share_data.html
AMB
"Keith G Hicks" wrote:

> Is it possible to join the results of a stored procedure with a table?
> SELECT field1, field2, field3 FROM tblCustomer INNER JOIN (exec spTest
> 'inputvar' AS SP) ON tblCustomer.CustID = SP.CustID
> Thanks,
> Keith
>
>|||Cool. That's what I'm doing. I just wasn't sure if there was a way to join
directly to the procedure. Thanks for the info.
"Alejandro Mesa" <AlejandroMesa@.discussions.microsoft.com> wrote in message
news:8D7D36E8-8EF7-4E4B-8613-59F8BC64148C@.microsoft.com...
Keith G Hicks,
You need to grab the result of the sp into a table (permanent or temporal)
and use the table in the join, or you can re-write the sp as a table
function.
create table #t1(c1 ...)
insert into #t1(c1, ...)
exec spTest 'inputvar'
SELECT field1, field2, field3
FROM tblCustomer INNER JOIN #t1 AS SP ON tblCustomer.CustID = SP.CustID
drop table #t1
go
How to share data between stored procedures
http://www.sommarskog.se/share_data.html
AMB
"Keith G Hicks" wrote:

> Is it possible to join the results of a stored procedure with a table?
> SELECT field1, field2, field3 FROM tblCustomer INNER JOIN (exec spTest
> 'inputvar' AS SP) ON tblCustomer.CustID = SP.CustID
> Thanks,
> Keith
>
>