SQL conditional parameter value
I need a multiselect parameter to be nullable, so in thinking about workarounds I thoug开发者_开发百科ht it would be pretty simple if only I could do something like :
SELECT STATEMENT{
...
}
IF @Door = null
@Door = '0000'
How can you work around null multi-value parameters?
You can use where door = coalesce(@door,door)
This will use the @door parameter if it is not null or use the value currently in the door column for that row.
Try this:
SELECT Foo
From Bar
WHERE ((@Door IS NULL AND Door = '0000')
OR (Door = @Door))
Just
SET @Door = COALESCE(@Door, '0000');
SELECT … /* using @Door */
Unless I'm missing something.
精彩评论