October 13, 2005 at 7:52 pm
Hi all, this is what I'm trying to do.
I have a stored procedure. Within the stored procedure I am declaring cursors, example...
Declare cSomeCursor Cursor for select * from servername.databasename.ownername.tablename (this is a linked server, but this doesn't really matter)
The PROBLEM is that I want to be able to call this stored procedure, and pass in the Servername as a parameter for declaring this cursor.
For example... EXECUTE spMyStoredProc @Servername = 'ServerA'
Then inside the stored procedure, the Servername parameter would be substituted somehow into the Cursors SQL statement declaration like so (but this code doesn't work obviously)
Declare cSomeCursor Cursor for select * from + @ServerName + .databasename.ownername.tablename
I've tried to do this a bunch of different ways, but I just can't get my brain wrapped around how to accomplish this. Any help?
October 13, 2005 at 8:52 pm
I'm pretty sure you'll need dynamic sql to pass the servername as a parameter, and also pretty sure you cannot declare a cursor in dynamic sql, so I don't believe there is any way to do what your trying.
I could be wrong.
October 14, 2005 at 1:26 am
Nope, I think you're exactly right. When I left work, I started thinking it through, it just doesn't seem logical that it's something that you can do. I posted here just in case, but I'm 90% sure it's not possible nor necessary.
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply