[英]Execute the value of a varchar returned from a “OUTPUT DELETED.[ColumnName]” statement
I am trying to use a table as a heap queue . 我试图将表用作堆队列 。 However I am having a little trouble figuring out how to take the text that is generated in the dequeue function and perform a execute on it.
但是,我在弄清楚如何获取在dequeue函数中生成的文本并对其执行执行时遇到了一些麻烦。
Here is the table storing the queue and the dequeue method. 这是存储队列和出列方法的表。
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
How do I get the varchar from deleted.[Sql_Text]
to a execute
statement? 如何从
deleted.[Sql_Text]
获取varchar到execute
语句?
Capture the output in a table variable and fill a varchar variable from the table variable. 捕获表变量中的输出并从表变量中填充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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.