[dba-SQLServer] Parameter Input for Bit Value

pcs at azizaz.com pcs at azizaz.com
Wed Jan 30 20:25:11 CST 2008


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



More information about the dba-SQLServer mailing list