此触发器不是由我编写的,也不与存储的proc原始文件一起使用,我对其进行了修改以供使用。在我看来,问题出在表的手动更新或在SQL Server Management Studio中的插入时,触发器之一可以正常工作。当触发器更新或由存储过程通过ODBC连接插入触发器时,它不会修改表,触发器也不起作用。如果禁用了触发器,则存储的Proc将按预期方式工作。因此,该错误似乎是某种形式的权限错误。这是触发器。 (使用2012年) 提前致谢 唐纳德·博森(Donald S. Bossen)
USE [JBI]
GO
/****** Object: Trigger [dbo].[send_ship_exec_info_to_p21] Script Date: 8/29/2018 3:22:26 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[send_ship_exec_info_to_p21] ON [dbo].[ship_exec]
FOR INSERT, UPDATE
AS
declare @pick_ticket_no varchar(50)
declare @tracking_no varchar(50)
declare @pickup_date varchar(50)
declare @carrier_id varchar(50)
declare @package_count varchar(50)
declare @delete_flag varchar(50)
declare @package_weight varchar(50)
declare @package_charge decimal(9,4)
declare @total_shipment_charge decimal(19,4)
declare @carrier_name varchar(50)
declare @customer_freight_charge decimal(9,4)
declare @saturday_delivery varchar(50)
declare @transaction_type varchar(50)
declare @billing_option varchar(3)
select
@pick_ticket_no = i.pick_ticket_no,
@tracking_no = i.tracking_no,
@pickup_date = i.pickup_date,--left(i.pickup_date,8),
@carrier_id = i.service_type,
@package_count = i.package_count,
@delete_flag = i.delete_flag,
@package_weight = i.package_weight,
@package_charge = i.package_charge,
@total_shipment_charge = i.total_shipping_and_handling_charge,
@saturday_delivery = i.saturday_delivery,
@transaction_type = i.transaction_type,
@billing_option = i.billing_option
from inserted i
if @transaction_type = 'Inv Return'
begin
declare @document_link_uid int
declare @document_link_area_uid int
declare @link_name varchar(255)
declare @link_path varchar(4099)
set @link_name = 'UPS shipment ' + cast(@pick_ticket_no as varchar(40)) + ': ' + @tracking_no
set @link_path = 'http://wwwapps.ups.com/WebTracking/processInputRequest?HTMLVersion=5.0&sort_by=status&term_warn=yes&tracknums_displayed=5&TypeOfInquiryNumber=T&loc=en_US&InquiryNumber1=' + @tracking_no + '&InquiryNumber2=&InquiryNumber3=&InquiryNumber4=&InquiryNumber5=&AgreeToTermsAndConditions=yes&track.x=28&track.y=2'
if @delete_flag = 'Y'
begin
update
PROPHET21.dbo.document_link
set
row_status_flag = '700'
,date_last_modified = getdate()
,last_maintained_by = 'Ship Exec Delete Flag'
where
key1_cd = 'return_number'
and key1_value = @pick_ticket_no
and link_path like '%' + @tracking_no + '%'
end
if @delete_flag = 'N'
begin
if not exists(select document_link_uid from PROPHET21.dbo.document_link where link_path like '%' + @tracking_no + '%')
begin
exec @document_link_uid = PROPHET21.dbo.p21_get_counter 'document_link', 1
INSERT INTO
PROPHET21.dbo.document_link
(
document_link_uid
,source_area_cd
,key1_cd
,key1_value
,link_name
,link_path
,row_status_flag
,date_created
,created_by
,date_last_modified
,last_maintained_by
,outside_use_flag
,mandatory_flag
)
VALUES
(
@document_link_uid
,1312
,'return_number'
,@pick_ticket_no
,@link_name
,@link_path
,704
,getdate()
,'SHIP EXEC'
,getdate()
,'SHIP EXEC'
,'N'
,'N'
)
exec @document_link_area_uid = PROPHET21.dbo.p21_get_counter 'document_link_area', 1
INSERT INTO
PROPHET21.dbo.document_link_area
(
document_link_area_uid
,document_link_uid
,display_area_cd
,row_status_flag
,date_created
,created_by
,date_last_modified
,last_maintained_by
)
VALUES
(
@document_link_area_uid
,@document_link_uid
,1312
,704
,getdate()
,'SHIP EXEC'
,getdate()
,'SHIP EXEC'
)
end
end
end
if @transaction_type <> 'SWS' or not exists(select oe_pick_ticket.pick_ticket_no from PROPHET21.dbo.oe_pick_ticket oe_pick_ticket where oe_pick_ticket.pick_ticket_no = @pick_ticket_no)
return
if @transaction_type = 'SWS' and exists(select oe_pick_ticket.pick_ticket_no from PROPHET21.dbo.oe_pick_ticket oe_pick_ticket where oe_pick_ticket.pick_ticket_no = @pick_ticket_no)
begin
if (@delete_flag = 'Y')
begin
declare @invoiced_already varchar (50)
select @invoiced_already = oe_pick_ticket.invoice_no
from PROPHET21.dbo.oe_pick_ticket oe_pick_ticket
where pick_ticket_no = @pick_ticket_no
if(@invoiced_already is null)
begin
update PROPHET21.dbo.clippership_return_10004
set delete_flag = 'Y'
where tracking_no = @tracking_no
update PROPHET21.dbo.oe_pick_ticket
set freight_out = 0, date_last_modified = getdate(), last_maintained_by = 'Ship Exec void package'
where pick_ticket_no = @pick_ticket_no
end
return
end
if (@delete_flag = 'N')--@tracking_no like '1z%' and
Begin
declare @customer_pays_outgoing_freight char(1)
select
@customer_pays_outgoing_freight = freight_code.outgoing_freight
from
PROPHET21.dbo.oe_pick_ticket oe_pick_ticket
inner join PROPHET21.dbo.freight_code freight_code on oe_pick_ticket.freight_code_uid = freight_code.freight_code_uid and oe_pick_ticket.company_id = freight_code.company_id
where
oe_pick_ticket.pick_ticket_no = @pick_ticket_no
select
@carrier_name = carrier.name
from
PROPHET21.dbo.address carrier
where
carrier.id = @carrier_id
select @customer_freight_charge =
cast(case
when @billing_option in ('REC', 'TP', 'CB') then 0
when coalesce(@customer_pays_outgoing_freight, 'Y') = 'N' then 0
else ((@total_shipment_charge) / @package_count)
end as decimal(19,2))
update PROPHET21.dbo.oe_pick_ticket
set freight_out = isnull(freight_out, 0) + isnull(@customer_freight_charge, 0),
carrier_id = @carrier_id,
tracking_no = @tracking_no
where pick_ticket_no = @pick_ticket_no
insert into PROPHET21.dbo.clippership_return_10004
(pick_ticket_no,
tracking_no,
package_weight,
order_count,
shipped_date,
carrier_name,
total_charge,
processed_flag,
delete_flag,
date_created,
date_last_modified,
last_maintained_by,
line_number)
values
(@pick_ticket_no,
@tracking_no,
@package_weight,
@package_count,
@pickup_date,
@carrier_name,
@customer_freight_charge,
'N',
'N',
getdate(),
getdate(),
'SHIP EXEC',
0)
end
return
End