Solved

How to loop recordset and lock the table at stored procedure

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

759 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