我不得不在数据库中创建一个存储过程,似乎UPDATE语句无法正常工作(因为我尝试使用一些硬编码值,如下所示)
if exists (select * from dbo.sysobjects where id = object_id('[dbo].[Orders_CalculateTotals]') and OBJECTPROPERTY(id, 'IsProcedure') = 1)
drop procedure [dbo].[Orders_CalculateTotals]
GO
CREATE PROCEDURE [dbo].[Orders_CalculateTotals] AS
--@b_ref char(8)
DECLARE @TotalFlowerVal decimal(10,2)
DECLARE @TotalRelayCharge decimal(10,2)
DECLARE @TotalIntlCharge decimal(10,2)
DECLARE @TotalDiscount decimal(10,2)
DECLARE @OrderTotal decimal(10,2)
SELECT
@TotalFlowerVal = SUM(b_flower_val),
@TotalRelayCharge = SUM(b_relay_chg),
@TotalIntlCharge = SUM(b_intl_chg),
@TotalDiscount = SUM(b_disc),
@OrderTotal = SUM(b_total)
FROM
ord_item
WHERE
b_ref = 'ID102833'
GROUP BY
b_ref
UPDATE ord_head
SET a_tot_flower_val = '45.00',
a_tot_relay_chgs = @TotalRelayCharge,
a_tot_intl_chgs = @TotalIntlCharge,
a_tot_disc = @TotalDiscount,
a_total = @OrderTotal
WHERE
a_ref = 'ID102833'
当我在数据库中加载此特定记录的详细信息时,硬编码字段仍设置为NULL。同样值得一提的是,该过程在执行时不会抛出异常。另外,如果我在UPDATE
语句中拼写错误的字段名称,则会抛出异常(意味着至少要读取该语句)。
有人能看出这出现了什么问题吗?