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

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

SQL Statment with OpenQuery()

twu1
1-Visitor

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?

2 REPLIES 2
PaiChung
22-Sapphire I
(To:twu1)

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.

twu1
1-Visitor
(To:PaiChung)

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?

Announcements


Top Tags