尝试修改插入的数据库触发器。因此,如果StoreID等于6005,则插入一些文本,如果没有,则插入i。[BillEmail]。
INSERT INTO [FRTOOLS_Orders]
(OrderNumber, ShipFirstName, ShipLastName, ShipCompany, ShipStreet1, ShipStreet2, ShipStreet3, ShipCity, ShipState, ShipPostalCode, ShipCountryCode, BillPhone, BillFax, BillEmail, RequestedShipping, OrderID, OrderTotal, EmailNotification)
SELECT i.[OrderNumber],
i.[ShipFirstName] + ' ' + i.[ShipMiddleName],
i.[ShipLastName],
i.[ShipCompany],
i.[ShipStreet1],
i.[ShipStreet2],
i.[ShipStreet3],
i.[ShipCity],
i.[ShipStateProvCode],
i.[ShipPostalCode],
i.[ShipCountryCode],
i.[BillPhone],
i.[BillFax],
CASE WHEN i.[StoreID] = 6005 THEN 'sales@***.com' ELSE i.[BillEmail],
i.[RequestedShipping],
i.[OrderID],
i.[OrderTotal],
i.[BillEmail]
FROM inserted i
很可能这不是使用CASE语句的正确方法。 ''附近的语法错误'错误的语法'
答案 0 :(得分:0)
正如上面的评论所指出,你需要终止一个带有END
的CASE语句 INSERT INTO [FRTOOLS_Orders]
(OrderNumber, ShipFirstName, ShipLastName, ShipCompany, ShipStreet1, ShipStreet2, ShipStreet3, ShipCity, ShipState, ShipPostalCode, ShipCountryCode, BillPhone, BillFax, BillEmail, RequestedShipping, OrderID, OrderTotal, EmailNotification)
SELECT i.[OrderNumber],
i.[ShipFirstName] + ' ' + i.[ShipMiddleName],
i.[ShipLastName],
i.[ShipCompany],
i.[ShipStreet1],
i.[ShipStreet2],
i.[ShipStreet3],
i.[ShipCity],
i.[ShipStateProvCode],
i.[ShipPostalCode],
i.[ShipCountryCode],
i.[BillPhone],
i.[BillFax],
CASE WHEN i.[StoreID] = 6005 THEN 'sales@***.com' ELSE i.[BillEmail] END,
i.[RequestedShipping],
i.[OrderID],
i.[OrderTotal],
i.[BillEmail]
FROM inserted i
请注意,您的case语句可以包含多个WHEN子句(在这种情况下,这可能对您有用,也可能没用)
CASE
WHEN i.[StoreID] = 0 THEN '<unknown>'
WHEN i.[StoreID] = 6005 THEN 'sales@***.com'
WHEN i.[StoreID] IN (9997,9999) THEN 'sales@blahblah.com'
ELSE i.[BillEmail] END,