Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 passing varibales as SP input inside a cursor

Author  Topic 

rtutus
Aged Yak Warrior

522 Posts

Posted - 2007-02-25 : 11:09:37
Hi dear,
I want to assign the variable @myVar an input to my stored procedure parameter @myParam. But I want to do that my cursor code:

declare @myVar as..
fetch next from crsMyTblParams into @DBparam
while @@fetch_status=0 begin

EXEC sys.sp_helprotect @username=@myVar
fetch next from crsMyTblParams into @DBparam
end
close crsMyTblParams
deallocate crsMyTblParams


But that gives me an error

2/ another question pls: how can I use the same thing for a varibale like this:
declare @myDB
...cursor code
use @myDB....rest of cursor code
...end of cursor code


Is that possible , thank you

nr
SQLTeam MVY

12543 Posts

Posted - 2007-02-25 : 20:22:29
1. Not sure what you are trying to do here. Should the fetch use @myVar instead of @DBParam?
2. You can't use a use statement in an sp unless it's in dynamic sql

exec ('use ' + @myDB + ' exec ... select ...')

You will probably find this easier if you don't try to use a cursor. Create a temp table with the values you want and an identity and loop through it.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -