需要触发器的帮助。
如果我从where子句中删除我的内部联接,那么我猜这就是问题所在。如果我使用这个where子句它可以工作" WHERE oeordhdr_sql.A4GLIdentity = @ id"
任何帮助将不胜感激。以下是代码......
ALTER trigger [dbo].[bdordermakeonhold]
on [dbo].[oeordhdr_sql]
for insert
as
declare @edi as char(1)
declare @id as numeric(9,0)
declare @ordno as char(8)
declare @ordtype as char(1)
declare @cus_no as char(12)
declare @status as char(1)
declare @ship_to_addr_3 as char(40)
set @edi=(select edi_fg from inserted)
set @id=(select a4glidentity from inserted)
set @ordno=(select ord_no from inserted)
set @ordtype=(select ord_type from inserted)
set @cus_no=(select cus_no from inserted)
set @status=(select status from inserted)
set @ship_to_addr_3=(select status from inserted)
set nocount on
if @edi is null or @edi='E'
if not exists (SELECT ID, Cus_No, State, CertificateID, Expiration FROM BDSalesTaxCerts
WHERE State = 'FL' AND @cus_no = Cus_No)
begin
UPDATE oeordhdr_sql
SET status = 'C',hold_fg = 'H'
FROM inserted AS i INNER JOIN
oeordlin_sql AS LN ON LN.ord_no = i.ord_no INNER JOIN
ARCUSFIL_SQL as CS ON i.cus_no = CS.cus_no
WHERE oeordhdr_sql.A4GLIdentity =@id and cs.state not in ('FL','PR',' ','lima') and
(LN.loc = 'SE') AND (@ship_to_addr_3 LIKE '%FL%') AND @status in ('1')
if not exists (select ID from BDInvoiceSupport where Orig_Ord_no=@ordno and orig_ord_type
=@ordtype)
begin
INSERT INTO [dbo].[BDInvoiceSupport]
([ID]
,[LastUpdate]
,[RecordRevLevel]
,[Inv_No]
,[TaxProcessingStatus]
,[Orig_Ord_no]
,[orig_ord_type]
,[InvoiceSent]
,[OnHoldReason])
select NEWID(),GETDATE(),0,inv_no,0,ord_no,ord_type,0,'Not checked yet.'
from inserted
end
end
答案 0 :(得分:0)
如果一次插入两行,这会给你带来麻烦。您应该使用连接将其写入inserted
表,而不是使用变量。