Solved

How to loop recordset and lock the table at stored procedure

Posted on 2003-12-10
6
225 Views
Last Modified: 2012-08-13
-- Lock the Table
???? How to Lock e.g. OutboundQueueItems

-- Get recordset (0 to N JobItemdID) from a table
select ***JobItemID*** from OutboundQueueItems where JobID = 123 and IsLocked = 0 and AddToProcessing = 1

-- Loop to update () to N) ***JobItemID****            
???? How to get and loop
update OutboundQueueItem set isLocked = 1,  Status = 2 where JobItemID = ***JobItemID***
0
Comment
Question by:mscprojhk
  • 3
6 Comments
 
LVL 18

Expert Comment

by:ShogunWade
ID: 9911501
Could you please explain?  and clearly identify your question?
0
 
LVL 18

Expert Comment

by:ShogunWade
ID: 9911502
Could you please explain?  and clearly identify your question?
0
 

Author Comment

by:mscprojhk
ID: 9911541
Inside a sp, I want to

1. Lock the Table so that no update until sp finished
2. What's the syntax of putting values into array in sp and then used by other sql statement.

In my case,

select arrJobItemID from OutboundQueueItems where JobID = 123 and IsLocked = 0 and AddToProcessing = 1

The result should be 0 to N numbers of JobItemID (arrobItemID)

Then, I want to update their fields, IsLock and Status, say,
update OutboundQueueItem set isLocked = 1,  Status = 2 where JobItemID = arrJobItemID

I don't know the sntax at sp.
0
 
LVL 18

Accepted Solution

by:
ShogunWade earned 20 total points
ID: 9911642
1) You should use BEGIN TRAN, COMMIT TRAN and ROLLBACK to secure your record integrity in the SP.

2) there is no array concept in SQL Server.   You should use temporary tables or table variables.   however your example would suggest that you dont need to do this anyway.

update OutboundQueueItem set isLocked = 1,  Status = 2 where JobID = 123 and IsLocked = 0 and AddToProcessing = 1
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SSRS 2013 - Creating a summarized report 19 36
Webservices in T-SQL 3 31
TSQL query to generate xml 4 35
Tsql query 6 22
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question