2 Replies Latest reply on Dec 16, 2016 9:08 PM by twu RSS
    twu Explorer

    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?

      • Re: SQL Statment with OpenQuery()
        pchung Collaborator

        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()
            twu Explorer

            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?