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.
| Author |
Topic |
|
Babli
Yak Posting Veteran
53 Posts |
Posted - 2007-02-08 : 01:44:19
|
| Hi,I have an input parameter when its true there should be a union.My stored proc should look something:SELECT * FROM TABLE1if @param is true thenSELECT * FROM TABLE1UNIONSELECT * FROM TABLE2ELSESELECT * FROM TABLE1.How do i do this.Help needed. |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-02-08 : 01:51:23
|
| [code]If @param = 1Begin Select * from Table1 Union all Select * from Table2EndElseBegin Select * from Table1End[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-02-08 : 02:14:05
|
[code]SELECT * FROM TABLE1UNIONSELECT * FROM TABLE2WHERE @param = 1[/code] KH |
 |
|
|
Babli
Yak Posting Veteran
53 Posts |
Posted - 2007-02-08 : 02:14:28
|
Thanks a tonquote: Originally posted by harsh_athalye
If @param = 1Begin Select * from Table1 Union all Select * from Table2EndElseBegin Select * from Table1End Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED"
|
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-02-08 : 02:18:58
|
quote: Originally posted by khtan
SELECT * FROM TABLE1UNIONSELECT * FROM TABLE2WHERE @param = 1 KH
Will not that be slightly more costly?Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-02-08 : 02:41:39
|
Yes. slightly KH |
 |
|
|
|
|
|