views:

647

answers:

1

How can I return a OpenQuery in SQL Server including a variable to a cursor?

DECLARE curMyCursor CURSOR FOR EXEC('SELECT * FROM OPENQUERY(SYBASE, ''SELECT * FROM MyTable WHERE MyPrimaryKey=''''' + @Variable + ''''''')')

OPEN @ResultCrsr

+2  A: 

you don't. put the open query result into a temo table and open a cursor on it.

but why do you need a cursor at all?? i'm sure there's a better way of doing things without it.

Mladen Prajdic