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
 General SQL Server Forums
 New to SQL Server Programming
 exec in select statement

Author  Topic 

maya_zakry
Constraint Violating Yak Guru

379 Posts

Posted - 2007-01-02 : 20:16:48
hi,

can somebody tell me how to call SP in another SP select statement..? i've seen ppl doing it something like this..

Select column1, coulumn2, (select EXEC SP_NAme), blabla

thanks in advance... :)

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-01-02 : 20:59:57
You can call one SP in other using EXEC like this:

Create Proc p1
as
begin
Exec p2 param1, param2, ...
end


But I don't think you can nest EXEC within SELECT statement.


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

maya_zakry
Constraint Violating Yak Guru

379 Posts

Posted - 2007-01-02 : 23:04:05
hi harsh,
using that method, the datarecord will split in two tables, where as i need it to combine with existing select statement.. meaning i need to treat the sp as another new columns :-

my result :-
abc,10,F,nanny, <--- from my main select
abc,fri,78,pp,foo,33,bar <--- from another SP

combine, and get 1 row record :-
abc,10,F,nanny,abc,fri,78,pp,foo,33,bar

NOTE: Not considering join method for some reason
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-02 : 23:06:14
quote:
Originally posted by maya_zakry

i've seen ppl doing it something like this..

Select column1, coulumn2, (select EXEC SP_NAme), blabla
I seriously doubt that...


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-02 : 23:07:16
quote:
Originally posted by maya_zakry

NOTE: Not considering join method for some reason
Why?
If not, you must resort to UNION operator together with GROUP BY and a lot of aggregated MAXs.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-02 : 23:08:06
Why not have a new SP that outputs the record you want?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-01-03 : 09:32:53
Create table #t1(id int identity(1,1),.....)
Insert into #t1 EXEC proc1

Create table #t2(id int identity(1,1),.....)
Insert into #t2 EXEC proc2

Now join the tables using id

But I want to know where you want to display these?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -