Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to do var substitution?
Message
From
30/01/2001 18:07:19
 
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00470308
Message ID:
00470399
Views:
45
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform