sql server 2008 - IF ELSE CONDITION IN SQL WHERE CLAUSE -


my query

declare @autoapprove bit         set @autoapprove = (             select autoapprove             dbo.commentbox_setting             usermoduleid = @mymoduleid                 , portalid = @portalid                 , culturecode = @culturecode             ) 

from whether 1 or 0 (true or false) furthermore have

   select * comentbox_comment                 uppermoduleid = @uppermoduleid                     , moduleid = @mymoduleid                     , portalid = @portalid                     , culturecode = @culturecode                     , //here need check condition  

(if(@autoapprove=0){ isapprove=1}else {do not check})

note here isapprove table filedname

i know ,i can long query need short , easy way. me out.

try like

and case when @autoapprove=0 isapprove else 1 end = 1 

this check isapprove = 1 if @autoapprove = 0, or 1=1(ignore) otherwise.

case (transact-sql)


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -