Say I have a table where each row is a query in a string representation
假设我有一个表,其中每一行都是字符串表示形式的查询
'select * from foo1'
'select * from foo1'
'select * from foo2'
'select * from foo2'
'select * from foo3'
'select * from foo3'
Is it possible to evaluate all the queries at once?
是否可以一次评估所有查询?
1 个解决方案
#1
0
Change QueryString and TableName in the code below to reflect your table info. Nothing else needs to be changed.
在下面的代码中更改QueryString和TableName以反映您的表信息。没有别的东西需要改变。
DECLARE @Query varchar(50);
DECLARE query_cursor CURSOR FOR
SELECT QueryString FROM TableName;
OPEN query_cursor;
FETCH NEXT FROM query_cursor
INTO @Query;
WHILE @@FETCH_STATUS = 0
BEGIN
EXEC (@Query);
FETCH NEXT FROM query_cursor
INTO @Query;
END
CLOSE query_cursor;
DEALLOCATE query_cursor;
#1
0
Change QueryString and TableName in the code below to reflect your table info. Nothing else needs to be changed.
在下面的代码中更改QueryString和TableName以反映您的表信息。没有别的东西需要改变。
DECLARE @Query varchar(50);
DECLARE query_cursor CURSOR FOR
SELECT QueryString FROM TableName;
OPEN query_cursor;
FETCH NEXT FROM query_cursor
INTO @Query;
WHILE @@FETCH_STATUS = 0
BEGIN
EXEC (@Query);
FETCH NEXT FROM query_cursor
INTO @Query;
END
CLOSE query_cursor;
DEALLOCATE query_cursor;