Reputation: 31
select @dbName="DBNAME"
select Distributorid from [180.552.528.854,21414].[@dbName].DBO.DistributorMaster where Distributorid =XXXXXX
ERROR: The OLE DB provider "SQLNCLI10" for linked server[180.552.528.854,21414] does not contain the table ""@dbName"."DBO"."DistributorMaster"". The table either does not exist or the current user does not have permissions on that table.
Upvotes: 2
Views: 182
Reputation: 3096
Try This. Dynamic variable value query .
declare
@dbname nvarchar(max) ='dbName',
@query nvarchar(max) ='select Distributorid from [180.552.528.854,21414].[@dbName].DBO.DistributorMaster
where Distributorid =XXXXXX'
SET @Query=REPLACE(@Query,'@dbname',@dbname)
--print(@Query)
execute SP_executesql @Query
Upvotes: 4
Reputation: 4647
When querying the Linked Server, you need to specify the fully qualified table name in the following pattern:
SERVER.DATABASE.SCHEMA.OBJECT
In addition to this, please check whether the table is listed on the Linked Server with the help of SQL Server Management Studio, under the Linked Servers
.
EDIT: Please check this site, if you've implemented all the steps noted on this site completely.
And also a common point that should've been missed is the following:
Adding ", @datasrc=@ServerName"
to your sp_addlinkedserver
statement.
Upvotes: -1