Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
foralexstar
Starting Member
4 Posts |
Posted - 2010-12-21 : 11:54:25
|
I have a stored procedure used by a Puller records program.The purpose of it is to select one row and update a status field, so next time when it is executed, the same row would't be returned.I am trying to avoid a potential table lock by using next script:CREATE PROCEDURE [dbo].[sp_GetQueueItems] @SubscriptionID AS int AS UPDATE TOP (1) [Queue]set [Queue].[Status] = 'P'WHERE [Queue].[Status] = 'O'and SubscriptionID=@SubscriptionIDSELECT * FROM INSERTEDGO When I try too execute it, I receive an error:Invalid object name 'INSERTED'I do not understand why I am getting it. Normally, it is when my inserted is out of scope. But here, in my case, it is should be OK.Any suggestions? |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
foralexstar
Starting Member
4 Posts |
Posted - 2010-12-21 : 12:01:10
|
I am trying to use INSERTED trigger table. What would be solution in my case? |
 |
|
sanjnep
Posting Yak Master
191 Posts |
Posted - 2010-12-21 : 12:07:54
|
You need to create a trigger and pass the value from inserted table to physical table. Inserted table can't access outside the scope of trigger.gocreate trigger tr_updatefor update on xxx_tablenameastruncate table xxx_already_table insert into xxx_already_table from insertedgoNow you can do select * from xxx_already_tableThanks,Sanjeev |
 |
|
Kristen
Test
22859 Posts |
Posted - 2010-12-21 : 12:13:15
|
UPDATE TOP (1) [Queue]set [Queue].[Status] = 'P'OUTPUT Inserted.Col1, Inserted.Col2, ... INTO @UpdatedWHERE [Queue].[Status] = 'O'and SubscriptionID=@SubscriptionIDSELECT * FROM @Updated |
 |
|
foralexstar
Starting Member
4 Posts |
Posted - 2010-12-21 : 12:28:52
|
Thank you Kristen!This is exactly what I need!Alex. |
 |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|