开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜