Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 from insert

Author  Topic 

doran_doran
Posting Yak Master

179 Posts

Posted - 2009-12-08 : 11:23:56
How is this looking?

CREATE TRIGGER [it_Orders_to_FillOrders]
ON [Orders]
FOR INSERT
AS

BEGIN TRY
INSERT INTO [FillOrders].[dbo].[tblFillOrders]
(
orderid,
orderprice,
orderdesc,
quantity
)
SELECT
o.orderid,
o.orderprice,
od.description,
o.quantity
FROM orders o
left outer join OrdersDescription od
on o.orderid = od.OrderID

END TRY

DECLARE @runDateTime datetime = GETDATE(),
@UserName varchar(100) = system_user

BEGIN CATCH
INSERT INTO [FillOrder].[dbo].[logs]
(username,
logdatetime,
tablename,
useraction,
COMMENT)

VALUES (
@UserName,
@runDateTime,
'tblFillOrders',
'Insert',
'Attempt Failed')
RETURN 1
END CATCH

-- Rollback the transaction if there were any errors

IF @@ERROR <> 0
BEGIN
ROLLBACK -- ROLLBACK THE TRANSACTION
RETURN 0
END

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-12-08 : 11:25:34
Did you see tara's reply from here?

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=136725
Go to Top of Page
   

- Advertisement -