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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 CASE statement on a WHERE clause?

Author  Topic 

vicpal25
Starting Member

21 Posts

Posted - 2008-04-17 : 13:59:57
I need to have a CASE statement inside a WHERE clause. Is this possible? Here is my WEHRE clause. Any suggestions are appreciated:


WHERE
--r.pBOM_ID=d.fEngr_BOM_ID and
r.fItem_ID=a.pEngr_Item_ID and
r.level<=@v_level+1 and
case when @v_showrootlevel=1 then r.level>1 else r.level>1 end
order by r.pID

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-17 : 14:06:24
Whats the purpose of this case statement? its reurning same value for all cases?
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2008-04-17 : 14:09:10
case when @v_showrootlevel=1 then r.level>1 else r.level>1 end

maybe
and ((@v_showrootlevel=1 and r.level>1)
or (@v_showrootlevel<>1 and r.level<=1))

I guess you wnat one to be >1 and the other <=1 not both >1



==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

vicpal25
Starting Member

21 Posts

Posted - 2008-04-17 : 14:36:23
sorry, I forgot to change a value:

WHERE
--r.pBOM_ID=d.fEngr_BOM_ID and
r.fItem_ID=a.pEngr_Item_ID and
r.level<=@v_level+1 and
case when @v_showrootlevel=1 then r.level>1 else r.level>0 end
order by r.pID
Go to Top of Page
   

- Advertisement -