xcaliber2222
Programmer
Hello,
I'm firing this insert trigger but no data is being returned to the email, I think because it is firing before the commit:
I've verified that there are no null values once the record has been inserted. Am I trying to grab data that hasn't been inserted yet? If anyone could help me out I'd really appreciate it.
Thanks,
Alejandro
I'm firing this insert trigger but no data is being returned to the email, I think because it is firing before the commit:
Code:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER TRIGGER [dbo].[trTestNotifyShipperIns] ON [dbo].[flight] FOR INSERT AS
BEGIN
Declare @flight_id as varchar(32)
Select @flight_id = flight_id FROM inserted
Declare @airline_name as varchar(32)
Declare @flight_num as varchar(32)
Declare @pu_id as varchar(32)
Declare @dep_airport_id as varchar(4)
Declare @arr_airport_id as varchar(4)
Declare @dep_sch_dttm as varchar(32)
Declare @dep_act_dttm as varchar(32)
Declare @arr_sch_dttm as varchar(32)
Declare @contact_email as varchar(100)
Declare @customer_name as varchar(100)
Declare @NewLineChar AS varchar
SET @NewLineChar = CHAR(13) + CHAR(10)
SELECT
@flight_id = f.flight_id,
@airline_name=a.name,
@flight_num=f.flight_num,
@pu_id=j.pickup_id,
@dep_airport_id=f.dep_airport_id,
@arr_airport_id=f.arr_airport_id,
@dep_sch_dttm=f.dep_sch_dttm,
@dep_act_dttm=f.dep_act_dttm,
@arr_sch_dttm=f.arr_sch_dttm,
@customer_name=c.name,
@contact_email=j.shp_notify_addr
FROM flight f INNER JOIN
itinerary_dtl i ON f.flight_id = i.item_id INNER JOIN
job j ON i.itinerary_id = j.itinerary_id INNER JOIN
airline a ON a.airline_id = f.airline_id INNER JOIN
customer c ON j.cust_code = c.cust_code
WHERE i.item_type = 'F' AND j.cust_code = '111111' AND f.flight_id = @flight_id
END
/* BEGIN EMAIL */
BEGIN
Declare @email_message as varchar(2000)
set @email_message = 'Here is your (updated) flight information for PU#' + @pu_id + '<BR>' + 'Airline: ' + @airline_name + '<BR>' + 'Flight Num: ' + @flight_num + '<BR>' + 'Departing Airport: ' + @dep_airport_id + '<BR>' + 'Arriving Airport: ' + @arr_airport_id + '<BR>' + 'Scheduled Departure Time: ' + @dep_sch_dttm + '<BR>' + 'Actual Departure Time: ' + @dep_act_dttm + '<BR>' + 'Scheduled Arrival Time: ' + @arr_sch_dttm
INSERT INTO test_email([send_to], [send_from], [subject], [body], [body_format])
VALUES('softdev@test.com', 'system@test.com', 'Flight Info for ' + @customer_name, @email_message, 'HTML')
END
I've verified that there are no null values once the record has been inserted. Am I trying to grab data that hasn't been inserted yet? If anyone could help me out I'd really appreciate it.
Thanks,
Alejandro