Author |
Topic |
Clages1
Yak Posting Veteran
69 Posts |
Posted - 2008-10-17 : 14:27:59
|
hi, i would like to doSelect a,b,c from Table Aunion Select x,y,z from Table Bunion If @saldo = 'S' Select x,y,z from Table C else Select x,y,z from Table D end-ifI get error in If statementTksClages |
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2008-10-17 : 14:35:14
|
declare @saldo varchar(10)set @saldo='s'If @saldo = 'S' Select a,b,c from TableAunion Select x,y,z from TableBunion Select x,y,z from TableCelse Select a,b,c from TableAunion Select x,y,z from TableBunion Select x,y,z from TableD |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-18 : 02:26:03
|
no need of if elseselect *from(Select a as val1,b as val2,c as val3,1 as cat from Table Aunion Select x,y,z,2 from Table Bunion Select x,y,z,3 from Table CunionSelect x,y,z,4 from Table D)twhere (@saldo='S' and cat<> 4)or (@saldo<>'S' and cat<> 3) also if you're sure that A,B,C,D wont have same records in them then use union all instead of union. union takes distinct after selection so will have an impact on performance. |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-10-18 : 03:05:43
|
Select a,b,c from Table Aunion Select x,y,z from Table Bunion Select x,y,z from Table C where @saldo = 'S' unionSelect x,y,z from Table D where @saldo <> 'S'MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|