May 21, 2012 at 8:20 am
Is there a way, I can use a Global TAG (connection STRING) to refer to DB objects?
For example:
SERVER1.DB1.DBO.Table1
SERVER1.DB1.DBO.Table2
SERVER1.DB1.DBO.Table3
SERVER2.DB2.DBO.Table1
SERVER2.DB2.DBO.Table2
SERVER2.DB2.DBO.Table3
Let us say
CS1 = SERVER1.DB1.DBO
CS2 = SERVER2.DB2.DBO
My query is
select * from CS1.Table1
Select * from CS2.Table1
Can I do query I this, the problem I have is, some times the Connection information changes, so that I can maintain them in one place.
Thanks in advance,
May 21, 2012 at 8:30 am
personally, I disklike them, but synonyms... http://msdn.microsoft.com/en-us/library/ms177544.aspx
May 21, 2012 at 9:20 am
Thanks, this is what I was looking for. But one issue I found. It needs all four parts. Is there a way I can create without using object, so that I can use one SYNONYM for multiple objects.
for example CREATE SYNONYM SER1 for SERVER1.DB1.DBO
then use as below:
select top 10* from SER1.Table1
select top 10* from SER1.Table2
select top 10* from SER1.Table3
May 21, 2012 at 9:43 am
May 21, 2012 at 11:07 pm
Yes, I agree with Steve....you need to use Dynamic SQL for this as follows:
Declare @name1 varchar(max) = 'abhi.Test.dbo', @name2 varchar(50) =
'Test', @name3 varchar(max), @sql varchar(max)
Select @name3 = @name1+'.'+@name2
Select @sql = 'Select * From '+@name3+';'
Execute (@sql)
May 23, 2012 at 5:48 am
adb2303 (5/21/2012)
Out of curiosity, why do you dislike synonyms?
May 23, 2012 at 6:19 am
SYNONYM is perfectly suit my need, and already implemented in my project. Thanks for all your help.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply