[dba-SQLServer]Is this possible?

Michael Brösdorf michael.broesdorf at web.de
Thu Feb 12 15:43:23 CST 2004


Hi,

i would like to pass a table name and a field name to a stored procedure.
The stored procedure has to create a cursor that fetches all records from
the table and performs certain operations based on the content of the
specified field.

Something like this:

Create procedure MyProc @MyTable nvarchar(255), @MyField nvarchar(255) AS

Declare @MyVar as int

Declare MyCursor cursor for
select <@MyField> from <@MyTable>

Fetch next from MyCursor into @MyVar

While @@Fetchstatus=0
begin
	...
	Print @MyVar
	...
end


The problem is of course that I cannot simply put the variables containg
table and field name into the select statement of the cursor.

Is there any way this can be done?

Michael




More information about the dba-SQLServer mailing list