I am new to Ignition and also to sql. I am at the moment revising some of the sql qery code in ignition to point from factory talk historian tags from Vantage-Point to OLEDB (osipi server). Please find below the old script vs the new script. The new script returns with the following error
- caused by GatewayException: [PIOLEDB] [SQL Parser] [Line 1] Syntax error near 'As'.
- caused by SQLException: [PIOLEDB] [SQL Parser] [Line 1] Syntax error near 'As'.
Your help is highly appreciated.
OLD CODE
WITH Line1 As(
SELECT cast(localTimeStamp as datetime) as [datetime], valueAsFloat as [ABC123]
FROM dbo.History ('','System.Sources.FactoryTalk.ft-directory.Historians.Production Historian.Tags.P025001_ABC123_XICOND','{Root Container.Start Date.formattedDate}','{Root Container.End Date Graph.formattedDate}','FT-VantagePt')
), Line2 As(
SELECT cast(localTimeStamp as datetime) as [datetime], valueAsFloat as [DEF456]
FROM dbo.History ('','System.Sources.FactoryTalk.ft-directory.Historians.Production Historian.Tags.P025001_DEF456_XICOND','{Root Container.Start Date.formattedDate}','{Root Container.End Date Graph.formattedDate}','FT-VantagePt')
)
SELECT Line1.[datetime],
Line1.[ABC123],
NULL as [DEF456]
FROM Line1
UNION ALL
SELECT Line2.[datetime],
NULL as [ABC123],
Line2.[DEF456]
FROM Line2
NEW CODE
WITH Line1 As ( SELECT cast(time as datetime) as [datetime], value as [ABC123]
FROM picomp2 where tag like 'P025001_ABC123_XICOND' and time between {Root Container.Start Date.formattedDate} and {Root Container.End Date Graph.formattedDate}
), Line2 As( SELECT cast(time as datetime) as [datetime], value as [DEF456]
FROM picomp2 where tag like 'P025001_DEF456_XICOND' and time between {Root Container.Start Date.formattedDate} and {Root Container.End Date Graph.formattedDate}
)
SELECT Line1.[datetime],
Line1.[ABC123],
NULL as [DEF456]
FROM Line1
UNION ALL
SELECT Line2.[datetime],
NULL as [ABC123],
Line2.[DEF456]
FROM Line2