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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 case statement in a filter

Author  Topic 

MangoSkin
Starting Member

22 Posts

Posted - 2010-07-05 : 11:02:13
I am trying to use this inside a where clause
(case when @approved=1 then Tbl1.BoolValue =1 else (Tbl1.BoolValue =0 or Tbl1.BoolValue is null))

But get this error "Incorrect syntax near '='."
How can I correct this.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-07-05 : 11:11:07
(Tbl1.BoolValue = 1 and @approved=1) or ((@approved<>1 and (Tbl1.BoolValue =0 or Tbl1.BoolValue is null)))


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-07-05 : 11:37:10
Madhi meant this in WHERE clause without using CASE.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

MangoSkin
Starting Member

22 Posts

Posted - 2010-07-05 : 11:46:54
quote:
Originally posted by madhivanan

(Tbl1.BoolValue = 1 and @approved=1) or ((@approved<>1 and (Tbl1.BoolValue =0 or Tbl1.BoolValue is null)))


Madhivanan

Failing to plan is Planning to fail


Will this slow the query. It is running pretty slow after the new condition is added. SO I am thinking to split the query into two stored procs.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-07-06 : 02:16:05
quote:
Originally posted by MangoSkin

quote:
Originally posted by madhivanan

(Tbl1.BoolValue = 1 and @approved=1) or ((@approved<>1 and (Tbl1.BoolValue =0 or Tbl1.BoolValue is null)))


Madhivanan

Failing to plan is Planning to fail


Will this slow the query. It is running pretty slow after the new condition is added. SO I am thinking to split the query into two stored procs.


That would be good idea

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2010-07-06 : 03:58:26
http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/
http://sqlinthewild.co.za/index.php/2009/09/15/multiple-execution-paths/

--
Gail Shaw
SQL Server MVP
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-07-06 : 04:03:51
quote:
Originally posted by MangoSkin

I am trying to use this inside a where clause
(case when @approved=1 then Tbl1.BoolValue =1 else (Tbl1.BoolValue =0 or Tbl1.BoolValue is null))

But get this error "Incorrect syntax near '='."
How can I correct this.


You are missing the END part for the CASE clause.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -