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
 General SQL Server Forums
 New to SQL Server Programming
 Help a big dummy with a Trigger

Author  Topic 

michaelnicholas
Starting Member

3 Posts

Posted - 2011-12-13 : 14:50:37
I have a table which gets written to by an external web service via an XML bulk load operation.
In the data that gets written (usually one row at a time), I have a record in the last column that I need to populate every time a row gets added. I already have it working in a package that runs successfully when I run it manually. HOWEVER, when I add a trigger to the table to try and execute my package, the bulk insert fails and just creates temporary bulkload tables and the Header table gets locked up.


Here's what I have for the trigger. Is this causing some sort of killer loop? What should I be doing instead of this?

ON [dbo].[Header]
AFTER INSERT
AS EXEC xp_cmdshell 'dtexec /f "C:\SSIS_Packages\fs_AddOrderRecordID.dtsx"'



tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-12-13 : 14:58:05
You need to remove the package from your trigger. Instead, use T-SQL to populate the data that you need. Or probably better yet, do it as a calculated column.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

pnash
Starting Member

26 Posts

Posted - 2011-12-13 : 14:58:08

Try with Creating a agent job for " EXEC xp_cmdshell 'dtexec /f "C:\SSIS_Packages\fs_AddOrderRecordID.dtsx" and call it after Insert in your trigger.
Go to Top of Page

michaelnicholas
Starting Member

3 Posts

Posted - 2011-12-13 : 15:11:35
Tara do you mean a "computed column"? That method would be independent of a trigger entirely right? I'm trying to link that OrderRecordID to another table as well - do you think I could do this with a computed column? I need to do it every time an order arrives via the bulk insert (which is kinda misleading because it is usually only one order at a time).
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-12-13 : 15:12:47
Yes a computed column, sorry. If there is logic that needs to occur to link it to another table, then yes do this in a trigger. Just don't do this in a package inside a trigger. Add the code directly in the trigger instead.

If you can write out the business requirements, we can probably write the trigger for you.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

michaelnicholas
Starting Member

3 Posts

Posted - 2011-12-14 : 10:50:12
Great! I appreciate your help Tara.. I really want to try to figure out/learn to write the trigger myself. I'll let you know if I get totally stumped!
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-12-14 : 11:44:08


Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -