Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Pass array of values from trigger to stored procedure, then cycle through array values in stored procedure

$
0
0

I'm confused. I'm a programmer, but have very little experience programming in SQL Server. Working on a project designed by someone else and we need to make some changes to the existing trigger/stored procedure to minimize deadlock issues.

Trigger fires whenever one of three fields is updated in the table. Trigger calls the stored procedure, and the stored procedure runs some various logic steps and then modifies one field on each of the records that were updated to one of two possible values depending on the outcome of the logic steps.

I want to take the trigger's inserted table, grab the uniqueid of each doc in that table, and then pass those values into the stored procedure.

SQL Server 2008 R2. TVP sounded like a good idea, so I started looking into that. The problem I've run into is I don't know how to loop through the values in the TVP once I get to the stored procedure. Numerous pages I've read have said that SQL programming isn't intended for looping. Well, I don't know how else to achieve the logic in the stored procedure. It involves multiple steps of comparing two different date values, as well as checking information from another table in the database.

Can somebody help me figure out how to loop through the TVP (even though it's not recommended) or give me some other way to pass the values in a way that I can access them individually in the SP?

Also, it's likely that multiple instances of the trigger will be running at the same time, in case that's relevant.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



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