2012-11-06 52 views
0

我試圖使用表格作爲heap queue。但是,我在計算如何獲取在出列函數中生成的文本並對其執行執行時遇到了一些問題。執行從「OUTPUT DELETED。[ColumnName]」語句返回的varchar的值

下面是存儲隊列和出隊方法的表。

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]execute聲明VARCHAR?

回答

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)