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 |
|
j11SqlTeam
Starting Member
1 Post |
Posted - 2009-03-02 : 22:50:49
|
| How do I properly write the following?IF(@ParamVar > 0) Execute (SELECT * FROM TABLE1)ELSE Execute (SELECT * FROM TABLE1 UNION SELECT * FROM TABLE2)Thank you! |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-03-02 : 23:07:51
|
| IF(@ParamVar > 0)Execute ('SELECT * FROM TABLE1')ELSEExecute ('SELECT * FROM TABLE1 UNION SELECT * FROM TABLE2') |
 |
|
|
matty
Posting Yak Master
161 Posts |
Posted - 2009-03-02 : 23:40:31
|
| IF(@ParamVar > 0) SELECT * FROM TABLE1ELSE SELECT * FROM TABLE1 UNION SELECT * FROM TABLE2 |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-03-02 : 23:42:34
|
| IF(@ParamVar > 0)SELECT * FROM TABLE1ELSEbeginSELECT * FROM TABLE1 UNION SELECT * FROM TABLE2endrememeber while using union the select columns should be same no of columns and same datatype |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-03-03 : 02:40:04
|
| Will this work?SELECT * FROM TABLE1 UNIONSELECT * FROM TABLE2 WHERE @ParamVar <= 0MadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-03-03 : 09:16:56
|
quote: Originally posted by madhivanan Will this work?SELECT * FROM TABLE1 UNIONSELECT * FROM TABLE2 WHERE @ParamVar <= 0MadhivananFailing to plan is Planning to fail
yup it will Also adding to that both tables should have same number of columns with corresponding ones of same type. If its certain that duplicates dont exist, use UNION ALL instead of union. |
 |
|
|
|
|
|