Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to do var substitution?
Message
De
30/01/2001 18:07:19
 
 
À
30/01/2001 17:19:27
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00470308
Message ID:
00470399
Vues:
42
Michael,

Thanks for your suggestion.

I actually tried something like this on my first go around. But again, I could not figure out the syntax. That is I have var called @dbname, and I tried things like USE @dbname or setting another var with something like SELECT @cmd = "use " + @dbname then EXEC (@cmd) but either I got an error because of invalid syntax or sql server never actually changed dabatases.

I'm now thinking of putting a SP in each database then having a SP in master create a cursor of all databases and then doing something like
exec ('dbname.mysp') in a loop.

I'll keep playing with it.

Regards,
-Isaac

>TSQL does not allow you to parameterize the FROM clause of a query. What about making your cleanup routine a stored procedure. Prefix the name with sp_ and save it into the master database. Have another routine create a cursor of all the user databases and use dynamic sql to issue a USE command and execute your cleanup routine.
>
>-Mike
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform