Historian retrieve data

1.5k Views Asked by At

I have an Excel worksheet that I have the data pulled from a Historian database for emission tags in a Wonderware server. I need to know how i can write the SQL query that uploads data between two date ranges.starte date end date.

I have collected the data and display I want, I just dont know how I can implement between two date ranges the user types in on another form. I DONT KNOW HOW TO DO THIS.

I have tried nothing because im not sure how to implement a parameter query with excel.

SET QUOTED_IDENTIFIER OFF
SELECT * FROM OPENQUERY(INSQL, "SELECT DateTime, [AB01_PE01], [NU_DC01_DX01_DISPLAY],
 [NU_DC01_DX02_DISPLAY], [NU_DC02_DX01_DISPLAY], [NU_DC02_DX02_DISPLAY], 
 [NU_DC03_DX01_DISPLAY], [NU_DC03_DX02_DISPLAY], [NU_DC05_DX01_DISPLAY]

    FROM WideHistory
    WHERE wwRetrievalMode = 'Cyclic'
     AND wwCycleCount = 14
     AND wwVersion = 'Latest'
     AND DateTime >= '20190501 06:00:00.000'
     AND DateTime <= GetDate()")

what I want is where Datetime >= is I need to set up where it ask the user the start date and end date? I do not know how to do this in excel I am new to the historian add in.

1

There are 1 best solutions below

3
PiotrS On

Based on your comment response, I understand your real question is: how to parameterize SQL query in Excel. This video shows step by step guide to do that: https://youtu.be/xPalEw4xw1w?t=129