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 |
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2011-10-05 : 06:01:04
|
| Hi,In the sql query below, I believe i can not use if within where clause as you see below.So, how can I place these or statements within the where calause based on if statements?The point is, if there is no @SIA, then there should not be any records with field Pyear = @SIAsame principle for @SICThanksselect Pyear, field2, field3, etcfrom tblMainwhere Pyear in ('2000', '2003', '2004') AND qrt in (1, 2, 3) if (len(@SIA) > 0) begin OR (Pyear in (@SIA)) end if (len(@SIC) > 0) begin OR (Pyear in (@SIC)) end |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-05 : 06:05:46
|
it should be ...wherePyear in ('2000', '2003', '2004')AND qrt in (1, 2, 3)AND (len(@SIA) = 0 OR Pyear in (@SIA))AND (len(@SIC) = 0 OR Pyear in (@SIC))------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
arkiboys
Master Smack Fu Yak Hacker
1433 Posts |
Posted - 2011-10-05 : 06:18:39
|
| solved. Thanks |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-05 : 06:26:52
|
| wc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|