【发布时间】:2014-08-16 11:55:44
【问题描述】:
在 SQl server 2008 R2 中,我需要捕获 log() 参数的异常,它可能是 NaN 或 NULL 或负数。
BEGIN TRY
DECLARE @ab float
select @ab = log(c.ab) FROM t1 a inner join t2 c
on t1.id = t2.id
-- @ab is selected from a table, but I do not know how to
-- write the query for this case combined with capturing a possible exception.
END TRY
BEGIN CATCH
EXEC sys.sp_addmessage 60000, 16, 'log argument not positive'
RAISERROR (60000, 16, 1)
END CATCH
令我惊讶的是,log(null) 没有抛出异常!!!
我可以在这里使用“if”来抛出异常。
但是,@ab 将从表中选择,因此它来自列。
从表中选择@ab 时如何捕获异常?
谢谢
【问题讨论】:
-
如果从表中选择了@ab,那么它将具有值或为空。您在
log函数中所做的事情。发布该代码。
标签: sql sql-server sql-server-2008 exception windows-7