Solved

How to loop recordset and lock the table at stored procedure

Posted on 2003-12-10
6
235 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

860 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