Marcello, if you absolutely have to be able to achieve your goal with a single script, you could try iterating through the databases and running TSQL in the context of each database. An example is below with sp_executesql running sp_executesql from/in each database in the cursor loop. Note that @Tsql is static here, so it's declared outside of the cursor loop. However it could just as easily be built dynamically within the loop. This exampleapproach isn't easy. It might even seem a little convoluted. I'll let you be the judge.
Dave Mason
- 885
- 1
- 8
- 19
@Tsql string only needs to be created once...move it outside of the cursor loop.
Dave Mason
- 885
- 1
- 8
- 19