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
 Getting issue in SQL server 2008

Author  Topic 

kalyan.cse05
Yak Posting Veteran

74 Posts

Posted - 2011-04-21 : 08:15:16
Hi,
Please get the query below:

DECLARE @SELECT varchar(255)
Declare @TableName nvarchar(50)

Set @TableName= 'TEST_TABLE'

SELECT @SELECT = 'SELECT ' + @TableName + '.*, L.description FROM ' + @TableName + ' INNER JOIN OPENDATASOURCE(''SQLOLEDB'',''Data Source=xxx;User ID=xx;Password=xx'').Second_table.dbo.Language L ON L.Language_Code=+ @TableName +'.lkpLangID'

EXEC(@SELECT)

Now when we execute this query it is unable to read the field name lkpLangID though the field name is present in the table TEST_TABLE

I got the below error Message
Invalid column name 'lkpLang'.

Could some one please help me


kalyan Ashis Dey

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-04-21 : 08:19:23
try
DECLARE @SELECT varchar(1000)
or try printing the variable and executing that.

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

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2011-04-21 : 08:25:33
DECLARE @SELECT varchar(255)
Declare @TableName nvarchar(50)

Set @TableName = 'TEST_TABLE'

SELECT @SELECT = 'SELECT ' + @TableName + '.*, L.description FROM '
+ @TableName
+ ' INNER JOIN OPENDATASOURCE(''SQLOLEDB'',''Data Source=xxx;User ID=xx;Password=xx'').Second_table.dbo.Language L ON L.Language_Code='+ @TableName+'.lkpLangID'
EXEC(@SELECT)


Go to Top of Page
   

- Advertisement -