If this is not production code, you could consider the undocumented
procedure xp_execresultset. Here's an example:
create table sqlCommands (
i int identity(1,1) primary key,
insert into sqlCommands values (N'Select top 2 OrderID from Orders order
by CustomerID desc')
insert into sqlCommands values (N'Select top 4 CustomerID from Customers
order by CompanyName')
exec master..xp_execresultset N'select sql from tempdb..sqlCommands',
drop table sqlCommands
-- Steve Kass
-- Drew University
-- Ref: ACA15359-5760-46BB-A861-89FBA129D785
>i have a simple table which has a field called sql_command.
>i would like to have a query which runs all of the
>sql_commands, i would also like to do a simple search and
>replace on the contents of the field.
>select top 400 * from property
>i would like to execute the string as
>select * from property.
>i cannot get the syntax correct for this, is it even
>possible? thanks in advance for any help.