cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

SQL Statment with OpenQuery()

Newbie

SQL Statment with OpenQuery()

I have a sql statment:

select * from openquery(insql, 'select datetime,[Level_001.PV],[Level_002.PV] from widehistory where datetime >= "2016-12-14" and datetime <= "2016-12-16"')

it works.


but while I changed it to:

select * from openquery(insql, 'select datetime,' || [[TagNames]] || ' from widehistory where datetime >= "2016-12-14" and datetime <= "2016-12-16"')

it doesn't work, the result show me: Incorrect syntax near '|'.


what shall I do in this case


By the way, is there any sql script and java script examples?

Tags (1)
2 REPLIES 2

Re: SQL Statment with OpenQuery()

You probably need to use String substitution vs. Parameter substitution so use << >> vs. [[ ]]

Now please properly validate and secure the service because you do expose a risk of SQL injection this way.

Re: SQL Statment with OpenQuery()

It still shows me Incorrect syntax near '|' while I changed statment to SELECT * FROM OpenQuery(insql, 'select datetime,' || <<TagNames>> || ' from widehistory where datetime >= "2016-12-14" and datetime <= "2016-12-16"')

Is there any documentation about sql script and java script?