2
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.

3
  • declare @dbName varchar(50) = 'DBNAME'; Declare Local variable Commented Nov 28, 2016 at 7:53
  • 1
    Dynamic sql only. Commented Nov 28, 2016 at 7:56
  • have declared already Commented Nov 28, 2016 at 8:05

2 Answers 2

4

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
Sign up to request clarification or add additional context in comments.

Comments

-1

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.

1 Comment

yes all is working but when ever i use parameter its throw error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.