Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Troubleshoot
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01159501
Message ID:
01159506
Views:
13
>Hi All,
> I this simple t-sql statement:
>
>
>Declare @Meet char(10),
> @cmd varchar(20)
>
>set @Meet = 'Meet152'
>Select @Cmd = 'Use ' + @Meet
>exec(@cmd)
>
>When I execute this in a query analyzer, it completes successfully, however this does not opens a Meet152 database.
>
> What am I doing wrong here?
>
>Thanks so much!!!

It does, but not in your current batchm becuase you use dynamic SQL it open Meet152 DB in separate batch, if you try:
Declare @Meet char(10),
        @cmd varchar(20)

set @Meet = 'Meet152'
Select @Cmd = 'Use ' + @Meet + '; SELECT * from SomeTableWhichIsInMeet152'
exec(@cmd)
You will get result set
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform