0

我正在尝试将表用作堆队列。但是,我在弄清楚如何获取出队函数中生成的文本并对其执行执行时遇到了一些麻烦。

这是存储队列和出队方法的表。

CREATE TABLE [dbo].[Merge_Queued_Work](Sql_Text varchar(2000) NOT NULL)
GO

create procedure usp_dequeueWork
as
  set nocount on;
  delete top(1) from [Merge_Queued_Work] with (rowlock, readpast)
      output deleted.[Sql_Text];      
go

如何从语句中获取deleted.[Sql_Text]varchar execute

4

1 回答 1

2

在表变量中捕获输出并从表变量中填充一个 varchar 变量。

create procedure usp_dequeueWork
as
  set nocount on;

  declare @T table(Sql_Text varchar(2000))
  declare @S varchar(2000)

  delete top(1) from [Merge_Queued_Work] with (rowlock, readpast)
      output deleted.[Sql_Text] into @T;      

  select @S = Sql_Text from @T

  exec (@S)
于 2012-11-06T06:30:11.017 回答