Saturday, February 25, 2012

Pass a value dinamically into a cursor

Hello,
I need to pass a [server_name] value dinamically to the statement used in the definition of one cursor but... don=B4t know how.
I need use server_name dinamically:
declare login_cur cursor for
select [name]
from [server_name].master.dbo.syslogins
Best regardsHow about creating a stored procedure that looks like this? --
create procedure serversproc
@.sname char(20)
as
exec ('select * from ' + @.sname +'.master.dbo.sysdatabases')
go
exec serversproc MyServerName
Vikram Jayaram
Microsoft, SQL Server
This posting is provided "AS IS" with no warranties, and confers no rights.
Subscribe to MSDN & use http://msdn.microsoft.com/newsgroups.

No comments:

Post a Comment