DECLARE @use10percent INT
SELECT
@use10percent = COUNT(*)
FROM
[dbo].[CUSTOMER_ORDER] o
INNER JOIN
[dbo].[CUSTOMER] c ON c.ID = o.CUSTOMER_ID
INNER JOIN
[dbo].[CUST_ADDRESS] ca ON ca.CUSTOMER_ID = o.CUSTOMER_ID
AND ca.ADDR_NO = o.[SHIP_TO_ADDR_NO]
WHERE
o.[ID] = @CUST_ORDER_ID
AND (isnull(ca.STATE, c.STATE) IN ('AB','BC','MB','MT','NB','NS','ON','PQ','QC','SK','TX','NY'))
/**/
UPDATE SHIPPER_LINE
SET ACT_FREIGHT = CONVERT(DECIMAL(10, 2),
(CASE
WHEN CAST(ShipWeight AS Float) >= 400
THEN CAST(Rate AS Float) * 1.06
WHEN CAST(ShipWeight AS Float) < 400
THEN CASE
WHEN @use10percent = 0
THEN CAST(Rate AS Float) * 1.20
ELSE CAST(Rate AS Float) * 1.10 --New rate for Canada, TX, and NY
END
ELSE CAST(Rate AS Float)
END))
此觸發器的目標是當重量低於400磅且目的地州是紐約州,德克薩斯州或加拿大全部時,將運費加10%。它適用於客戶使用拖船地址(ca.state)並且增加10%的情況。但是,如果客戶是買方和目的地,則(ca.state)爲空,並且需要使用(c.state)。如果(ca.state)爲空且(c.state)爲NY,TX或加拿大,上面的代碼將添加全部20%。在條款中使用ISNULL
如何修復where子句以正確過濾?
你的問題是什麼? –
如何在ca.state爲空時使用where子句來使用c.state?當c.state是NY時,上面的代碼增加了20%,當我希望它只增加10%時。 – Ian