Solved

How to loop recordset and lock the table at stored procedure

Posted on 2003-12-10
6
263 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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

615 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