| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2006-11-02 : 07:46:56
|
| libby writes "Hey,I have three stored procedures which take the same set of parameters but get the data from three different tables. My requirement is to join these three procedures by sending the same set of parameters and getting one output.I tried to use UNIONcreate procedure sp1(@param1 varchar(5),@param2 varchar(5),@param3 varchar(5))ASBEGINEXEC sp_one @param1, @param2, @param3UNIONEXEC sp_two @param1, @param2, @param3UNIONEXEC sp_three @param1, @param2, @param3ENDGOBut this doesnt work. I get a syntax error near UNION.Please help..Thanks.Its sqlserver 2000, windows xp service pack2." |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-11-02 : 08:00:00
|
| set nocount oncreate table #a(...)insert #aEXEC sp_one @param1, @param2, @param3insert #aEXEC sp_two @param1, @param2, @param3insert #aEXEC sp_three @param1, @param2, @param3select * from #adrop table #a==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2006-11-02 : 08:01:31
|
| Create a temporary table with appropriate columns for the result set from the SProcs then:INSERT INTO #MyTempTableEXEC sp_one @param1, @param2, @param3INSERT INTO #MyTempTableEXEC sp_two @param1, @param2, @param3INSERT INTO #MyTempTableEXEC sp_three @param1, @param2, @param3SELECT *FROM #MyTempTableKristen |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-11-02 : 08:02:53
|
| lol - think that's one each Kristen==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2006-11-02 : 08:06:02
|
| I couldn't see khtan or peso around, so I jumped in - I need the post count! |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-11-02 : 20:22:17
|
quote: Originally posted by Kristen I couldn't see khtan or peso around, so I jumped in - I need the post count!
MadhivananFailing to plan is Planning to fail |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2006-11-02 : 22:21:59
|
The solutions above are more like a UNION ALL than a UNION.This would be more like a UNION:create table #a(...)create table #b(...)create table #c(...)insert #aEXEC sp_one @param1, @param2, @param3insert #bEXEC sp_two @param1, @param2, @param3insert #cEXEC sp_three @param1, @param2, @param3select * from #a unionselect * from #b unionselect * from #c Just pumping my post count. CODO ERGO SUM |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-11-02 : 22:50:00
|
quote: Originally posted by Kristen I couldn't see khtan or peso around, so I jumped in - I need the post count!
Hey I am in diff time zone. I am here now"I need the post count!" "Just pumping my post count."Can i join in  KH |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2006-11-03 : 06:45:29
|
| "This would be more like a UNION:"Personally I would prefer a single #TempTable and a SELECT DISTINCT for the results, rather than multiple #TempTables.Horses for Course though ...Kristen |
 |
|
|
|