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 |
ArnoldG
Starting Member
36 Posts |
Posted - 2014-01-25 : 09:16:34
|
Hi,I am running a SQL query in Excel with an external parameter PARAM from a cell with values 'Yes' or 'No':SELECT A,B,CFROM Table The C column either contains NULL or 1How do I filter in the WHERE clause so that I get:ALL results if PARAM is 'No'C= 1 if the PARAM is 'Yes'I tried several things with SELECT CASE, but up until now without any results.Can anyone help me out here ?Thx,Arnold |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2014-01-27 : 01:39:49
|
Try thisSELECT A,B,CFROM TableWHERE (PARAM ='No') or (C= 1 AND PARAM ='Yes')MadhivananFailing to plan is Planning to fail |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-01-27 : 07:38:08
|
quote: Originally posted by madhivanan Try thisSELECT A,B,CFROM TableWHERE (PARAM ='No') or (C= 1 AND PARAM ='Yes')MadhivananFailing to plan is Planning to fail
simply this would do it rightSELECT A,B,CFROM TableWHERE (@PARAM = 'No'OR C = 1) Assuming PARAM allows only values as Yes and No------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2014-01-27 : 08:10:58
|
quote: Originally posted by visakh16
quote: Originally posted by madhivanan Try thisSELECT A,B,CFROM TableWHERE (PARAM ='No') or (C= 1 AND PARAM ='Yes')MadhivananFailing to plan is Planning to fail
simply this would do it rightSELECT A,B,CFROM TableWHERE (@PARAM = 'No'OR C = 1) Assuming PARAM allows only values as Yes and No------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs
Yes it is MadhivananFailing to plan is Planning to fail |
|
|
ArnoldG
Starting Member
36 Posts |
Posted - 2014-01-27 : 09:01:55
|
visakh16 and madhivanan,Thanks for your help.This works perfectly ...and so simple !Thanks again.Arnold |
|
|
|
|
|
|
|