Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

SQL Trigger problems

$
0
0

We use a program called Fedex ShipManager. It integrates with a SQL 2008 database. I am trying to write a trigger that will copy some of what the fedex software writes to a different database. I have checked, there is no way to get the software to write to two separate databases. This trigger works when I insert the data, but it fails when the fedex software does it. Does anyone have any guesses as to why this would happen?

ALTER TRIGGER [dbo].[trg_FulfilmentRequest]
   ON  [Billing].[dbo].[ShipmentBilling]
   AFTER INSERT
AS 
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	--Check if the ReferenceCode is numberic
	
	DECLARE @ShipRequest varchar(50)
	SELECT @ShipRequest = ReferenceCode FROM INSERTED
	IF ISNUMERIC(@ShipRequest) = 1
	Begin
		--If the Reference Code is numberic convert it to an integer
		DECLARE @ShipRequestID INT
		SET @ShipRequestID = CONVERT(INT, @ShipRequest)

		--If the ReferenceCode is in CatalogData.dbo.ShipmentRequest
		IF EXISTS (SELECT * FROM [CatalogData].[dbo].[ShipmentRequest] WHERE [CatalogData].[dbo].[ShipmentRequest].[ShipmentRequestID] = @ShipRequestID)
		BEGIN
		 --Insert the data into CatalogData.dbo.ShippingInformation
			DECLARE @TrackingNum varchar(50)
			SELECT @TrackingNum = TrackingNumber FROM INSERTED
			INSERT INTO [CatalogData].[dbo].[ShippingInformation] (ShipmentRequestId, TrackingNumber)
			VALUES (@ShipRequestID, @TrackingNum);
		END
	END
END

I have tried commenting out various lines. It is the insert statement that causes the problem. It also causes the problem if the TrackingNumber is removed.

Thanks for any suggestions


Viewing all articles
Browse latest Browse all 4871

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>