troubleshooting Question

Dynamic SQL Cursor

Avatar of matthewrhoades
matthewrhoades asked on
SQL
6 Comments1 Solution300 ViewsLast Modified:
I have a stored procedure which runs a cursor for updating tables.  The procedure may execute against different servers with the same database structure depending on the configuration, my problem is supplying a dynamic server name.  See below.
declare myCursor cursor for select a.id, b.id from tableA as a join "myServer".db.dbo.tableB as b on b.id = a.id
 
declare @server varchar(50)
 
declare myCursor cursor for select a.id, b.id from tableA as a join @server.db.dbo.tableB as b on b.id = a.id

Open in new window

ASKER CERTIFIED SOLUTION
ralmada

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros