RE: HOWTO programmtically code 'use' in T-SQL

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: ATS (ATS_at_discussions.microsoft.com)
Date: 02/10/05


Date: Thu, 10 Feb 2005 11:39:07 -0800

Thanks everyone for the reply, but I have found the sad answer. It can not be
done. I found an rticle posted by a Gary Johnson who was trying to solve the
same problem. Basically, one can not pass a variable into the "use database"
statement or onto the "refix" of a select statement such as select * from
@MY_DB..MY_TABLE.

This is not the end of the world for me, as fortunately I have the option of
using Dynamic SQL (i.e. @QRY = 'use ' + @MY_DB).

BUT....

If I could make a wish, I would wish that in T-SQL for SQL Server 2000 there
was a programmatic way of changing a connection "currently being used"
database. Or put another way, I wish we could programmatically pass in a
variable to the "use database" statement.



Relevant Pages

  • Re: CreateProperty
    ... Whether you are sad or happy, ... Perhaps you meant "add a Table to another Database that you have opened". ... Set tdfEmpHrs = dbLink.CreateTableDef ... Set idxEmpHrs = .CreateIndex ...
    (comp.databases.ms-access)
  • Re: CreateProperty
    ... Whether you are sad or happy, ... Perhaps you meant "add a Table to another Database that you have opened". ... Set tdfEmpHrs = dbLink.CreateTableDef ... Set idxEmpHrs = .CreateIndex ...
    (comp.databases.ms-access)
  • Re: Query SQLServer
    ... I'm sad to confirm that. ... could have access to the database with the purpose ... Is there any dirty, ... You might want to look for another host, or get a VPS and do it yourself. ...
    (comp.lang.php)
  • Re: Query SQLServer
    ... I'm sad to confirm that. ... could have access to the database with the purpose ... my host does not install any extra software. ... Is there any dirty, ...
    (comp.lang.php)
  • Re: ADO Connection Timeout
    ... so what happens when a connection failure forces one station to revert ... to a local database? ... Further, you *will* have contention issues, Jet does not support record ... to the central server, but you are willing to live with periods where it ...
    (microsoft.public.data.ado)