【问题标题】:How to get rid of Warning message from customized Raiserror - SQL Server如何摆脱自定义 Raiserror 中的警告消息 - SQL Server
【发布时间】:2017-08-14 10:32:43
【问题描述】:

我想在未触发更新查询时在屏幕上显示一个弹出窗口。 我正在使用 Raiserror 引发错误并显示自定义错误消息,该消息显示在弹出窗口中。

if(some condition)
begin

update  Tab1vendorInside
set 
VendorBatchCode=a.VendorBatchCode,
Quantity=a.Quantity,--case  When (PlannedDispatchQty>=a.Quantity) then a.Quantity  Else 0 end,
OfferedForInspectionOn=convert(varchar(80),convert(date, getdate())),
[Time]=convert(varchar(8), convert(time, getdate())) ,
CTDTDSReference=a.CTDTDSReference,
Certificateupload=a.Certificateupload,
Active=a.Active
from @TP a
inner join Tab1vendorInside 
on a.ID=Tab1vendorInside.ID and
a.Material=Tab1vendorInside.Material
and Datepart(mm,a.PlannedDispatchQtyDate)=Datepart(mm,Tab1vendorInside.PlannedDispatchQtyDate)
and Datepart(year,a.PlannedDispatchQtyDate)=Datepart(year,Tab1vendorInside.PlannedDispatchQtyDate)
inner join Tab1Vendor
on Tab1Vendor.Material=a.Material and Tab1Vendor.ID=a.TaboneVendorID
and Datepart(mm,a.PlannedDispatchQtyDate)=Datepart(mm,Tab1Vendor.PlannedDateofDispatch)
and Datepart(year,a.PlannedDispatchQtyDate)=Datepart(year,Tab1Vendor.PlannedDateofDispatch)
end

else
begin
--if it enters else, logically it means that the data is updated.
begin try
select 16/0
end try
begin catch
RAISERROR('Quantity limit exceeded! Data insert/update failed.',16,1);  
end catch
end

它工作正常,但问题是,我收到了附加到我的自定义消息的附加消息。

超出数量限制!数据插入/更新失败。警告:空 值被聚合或其他 SET 操作消除。

我想摆脱 警告 Null 值被消除...等等 我该怎么做?

【问题讨论】:

    标签: sql sql-server raiserror


    【解决方案1】:

    试试这个:

    SET ANSI_WARNINGS OFF
    

    这将抑制您看到的警告。但是,看起来也可以通过在查询中的某处添加 NULL 检查来修复它。我不能说你的代码没有在哪里发布完整的细节。

    如果您确实选择了抑制警告的快速修复方法,只需确保您之后在代码中再次启用它,方法是执行以下操作:

    SET ANSI_WARNINGS ON
    

    【讨论】:

    • 其实我已经试过了。没有帮助。你能解释一下空值吗?我已经编辑了我的代码。它实际上是更新查询而不是插入
    • 现在我可以看到你的代码了,因为第 1 行的条件为假,所以在一个正在运行的代码块中发生了 raise 错误,因此它与你的 update 语句没有任何关系。
    • 查看由 sqlauthority 提供的警告的很好解释:blog.sqlauthority.com/2015/02/13/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-21
    • 1970-01-01
    • 2015-02-02
    • 2020-12-16
    • 1970-01-01
    • 2022-11-16
    相关资源
    最近更新 更多