Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Database name as Variable in a Join Query in SQL

Author  Topic 

punitw
Starting Member

1 Post

Posted - 2007-02-02 : 08:46:45
I have a very simple Join Query like
Select A, B , C
From Database1.dbo.Table1 Inner Join Database2.dbo.Table2

Now problem is that Database name for the project freuqently changes though Table1 and Table2 names remain constant.
How can I store Datbase name at a central place in a table or as a constant so that I can use them in above query. It will allow me to change them at one place without making changes in all the sps where they are used

nr
SQLTeam MVY

12543 Posts

Posted - 2007-02-02 : 09:15:11
You would have to use dynamic sql to do it.

Another option is to use views and update the views when the database name is changed.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -