Hi All,
I have a problem about assigning the results of an OPENQUERY. Please check the code below:
DECLARE @sqlString nvarchar(4000)
DECLARE @sqlString1 nvarchar(4000)
DECLARE @custName nvarchar(100)
SET @custID = 2
SET @sqlString1 = 'SELECT * FROM myTable WHERE CustID = ' + CAST( @custID as varchar(6))
SELECT @sqlString = 'SELECT CustName FROM OPENQUERY(DEEPACCESS,''' + @sqlString1 + ''')'
EXECUTE(@sqlString)
--
The above code works fine but i need something like
SELECT @sqlString = 'SELECT @custname=CustName FROM OPENQUERY(DEEPACCESS,''' + @sqlString1 + ''')'
EXECUTE(@sqlString)
By doing this i want to assign the CustName to the local variable @custName.
I tried to use a temp table but in that case i was not able to specify a where clause in @sqlString1. (i'd rather use linked_server.databasename.owner.tablename , but i read that this does not provide good performance )
Any suggestions about the problem are welcomed!
Thanks in advance,
Bahtiyar KARANLIK