[dba-SQLServer] Parameter Input for Bit Value

Stuart McLachlan stuart at lexacorp.com.pg
Wed Jan 30 22:18:47 CST 2008


I'd use only one parameter and another value for "All". (All = 2?) 
Then you can just use:


DECLARE @DiscardFlag INT
......
AND
(DiscardFlag = @Discard OR @Discard = 2)



On 31 Jan 2008 at 12:25, pcs at azizaz.com wrote:

> Hi,
> What's the best practice for setting up the sql syntax so 
> that a parameter for a bit column can provide all three 
> options:
> 0 (False)
> 1 (True)
> 0 or 1 (Both)
> 
> like in:
> 
> AND
> BRS.DiscardFlag = (@p2_DiscardFlagValue)
> 
> Fiddling with various options, I stopped at
> 
> AND
> BRS.DiscardFlag in (@DiscardFlagValueA , @DiscardFlagValueB)
> 
> so parsed in values must be
> 
> AND
> BRS.DiscardFlag in (1,1)
> 
> to only return records where flag is TRUE 
> 
> AND
> BRS.DiscardFlag in (0,0)
> 
> to only return records where flag is FALSE 
> 
> AND
> BRS.DiscardFlag in (0,1)
> 
> to return all records irrespective of Flag value
> 
> Is there another (better) way?
> 
> Regards
> Borge
> _______________________________________________
> dba-SQLServer mailing list
> dba-SQLServer at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/dba-sqlserver
> http://www.databaseadvisors.com
> 





More information about the dba-SQLServer mailing list