AnsweredAssumed Answered

Escape LessThan in OpenQuery

Question asked by GregMcFarlane on Jan 7, 2020
Latest reply on Jan 8, 2020 by GregMcFarlane

I am trying to abstract a way to get Attribute Samples without having to write a function table, and table valued function, and a linked server procedure for every attribute. 


if you care to comment on that goal , i would greatly appreciate it. 


My Question here is that I am trying to do an OpenQuery  using the FVT GetSampledValues 

The openquery is choking on the  LessThan sign 


I have tried all the simple things. 

Is this possible?  Is there a simple typo in here that I am missing? 


declare @sql nvarchar(max) = N'
SELECT * FROM PI_PSC.[Master].[Element].[GetSampledValues]
''Cylinder Units'', --Template
N''|Exhaust Temperature'', -- AttributeTemplatePath
N''Value'', -- ValueColumnName
N''UOM'', -- UnitOfMeasureColumnName
N''Error'', -- ErrorColumnName
NULL -- UnitOfMeasure

declare @oq nvarchar(max) = 'select * from openquery(pi_psc, ''' + @sql + ''' )'


execute sp_executesql @oq