Solved

How to loop recordset and lock the table at stored procedure

Posted on 2003-12-10
6
205 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
Comment Utility
Could you please explain?  and clearly identify your question?
0
 
LVL 18

Expert Comment

by:ShogunWade
Comment Utility
Could you please explain?  and clearly identify your question?
0
 

Author Comment

by:mscprojhk
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now