English 中文(简体)
如果参数是空洞的,则进行大范围检查
原标题:Don t check field if parameter is an empty string
  • 时间:2009-09-18 11:21:49
  •  标签:

我希望这样做。

(s.Reference = @Reference or @Reference =   )

但是,我有一小差错,说无法将Nvarchar改为大林。 那里正在发生什么。 如果投入参数是空洞的,我只想绕过这个提问。

最佳回答

关于<代码>SQL,最佳决定是:

SELECT  *
FROM    mytable
WHERE   s.Reference = @Reference
UNION ALL
SELECT  *
FROM    mytable
WHERE   @Reference IS NULL

它将优化其中一个询问,只执行其余询问(必要时使用索引)。

问题回答

参照是一个数字领域。 在此情况下,你可能想做:

(s.Reference = @Reference or @Reference is null)

当你将=试验条件列入试验条件时,你假定它会演奏。





相关问题
热门标签