Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Dynamically pass database name to USE
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01483661
Message ID:
01483669
Views:
53
Hi, Elgin,

I'm not positive on this- but I don't believe you can use dynamic SQL simply for a line of code that changes the database (using a USE).

The reason is that dynamic SQL returns to the previous context before it executed.

To the best of my awareness, you'd need to string together some statements with a semicolon...

i.e. USE MyDatabase ; select * from sometable where 1=0 , ETC.

Again, I'm not certain on this, but I didn't think you could execute a single line of dynamic SQL just to change database context.
Previous
Reply
Map
View

Click here to load this message in the networking platform