Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For starters, it would be helpful if you posted your code. Quite often SQL can be modified to process multiple values in a "Set-based" way. In other words, if you had a set of values to process, you could process them all simultaneously. </p> <p>There are many ways to accomplish this. You could pass in a delimited string and then parse that in your proc. Lots of ideas on the implementation of this <a href="https://stackoverflow.com/questions/314824/t-sql-opposite-to-string-concatenation-how-to-split-string-into-multiple-reco">here</a></p> <p>You could also pass in XML and "join" to the XML in your proc using <code>APPLY</code>.</p> <p>In SQL 2008+ you can use <a href="http://msdn.microsoft.com/en-us/library/bb510489.aspx" rel="nofollow noreferrer">Table Valued Parameters</a></p> <p>Because I don't know what exactly you're doing with the AreaID parameter, I don't know if I've answered your question so here is some more info. </p> <p>If you want to run a stored procedure asynchronously, your best bet is Service Broker which will allow you to put a parameter in a queue and separate thread(s) will process the queue. SQL manages all the ordering, locking, retry, spawning/killing threads etc. It's a very robust system.</p> <p>There is a comment on the question from a different user who seems to be connected to the OP concerning progress tracking. Here is a thought:</p> <p>You have a "queue" table that contains a batchid and the areaID parameter and a status flag. </p> <pre><code>CREATE TABLE asynchQueue ( RecNo INT IDENTITY(1,1) PRIMARY KEY CLUSTERED, BatchID INT, AreaID INT, Status TINYINT ) </code></pre> <p>Your C# app inserts into the queue table with a unique batch id for your app and call (to group your requests) </p> <p>You have a proc scheduled to run periodically like this:</p> <pre><code>CREATE PROC ProcessQueue AS BEGIN SET XACT_ABORT ON DECLARE @RecNo INT, @AreaId INT BEGIN TRAN SELECT TOP 1 @RecNo = recNo, @AreaID = areaId FROM AsynchQueue WITH ROWLOCK, XLOCK WHERE Status = 0 UPDATE AsynchQueue SET Status = 1 --Mark record as in progress WHERE RecNo = @RecNo COMMIT EXEC YourProc @AreaId UPDATE AsynchQueue SET Status = 2 -- Mark Record as complete WHERE RecNo = @RecNo END </code></pre> <p>Or the proc could contain a loop to process all records in the table. The proc could be scheduled or invoked on demand using sp_start_job as John Weldon suggested. </p> <p>You could then query status as follows:</p> <pre><code>SELECT COUNT(NULLIF(Status, 0))/COUNT(*) as PctComplete --in progress or complete div by total FROM AsynchQueue WITH NOLOCK WHERE BatchID = @yourBatchId </code></pre> <p>That query will give you the percent complete of your batch.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload