Cursor – Changing name table | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Cursor – Changing name table

Hallo, is it possible write statement with some parameter in after definition of cursur ?
I usually work with cursor, but in cycle i need to change name of table
Declare au_cursor Cursor FOR SELECT id,tabs FROM k_Tabs
Open au_cursor
Fetch Next FROM au_cursor into @id, @tabs WHILE (@@FETCH_STATUS = 0) BEGIN Set @tmp= @tabs ‘ @tmp is name of table which i reed from another table and work with it Declare ns_cursor Cursor
FOR set @sqlCommand=’Select ns, price from ‘[email protected]
execute(@sqlCommand) Open ns_cursor
Fetch Next From ns_cursor into @ns,@cena WHILE (@@FETCH_STATUS = 0)
BEGIN
.
.
.
Fetch Next From zar_cursor into @program,@interval1,@interval2,@zlavaPerc
END
Close ns_cursor
Deallocate ns_cursor
.
.
.
Fetch Next FROM au_cursor into @id, @tabDatabaza
END Close au_cursor
Deallocate au_cursor Error message Server: Msg 156, Level 15, State 1, Line 86
Incorrect syntax near the keyword ‘set’. Thanks, Lubo
Why do you want to use Cursor? Replace these
set @sqlCommand=’Select ns, price from ‘[email protected]
execute(@sqlCommand) by
execute(‘Select ns, price from ‘[email protected])
Madhivanan Failing to plan is Planning to fail
When i am using execute(‘Select ns, price from ‘[email protected]) then is problem with executing of statement Server: Msg 156, Level 15, State 1, Line 90
Incorrect syntax near the keyword ‘execute’.
Clearly tell us what you are trying to do
I think there must be set based approach to do the same thing Madhivanan Failing to plan is Planning to fail
]]>