Inserting data between SQL table and Wonderware Historian

579 views Asked by At

I'm trying to get values ​​from the Wonderware Historian to be read in the Report Builder. I got the SQL code below through the Historian Client Query, but this code does the select directly from an SQL view.

SET NOCOUNT ON
DECLARE @StartDate DateTime
DECLARE @EndDate DateTime
SET @StartDate = DateAdd(mi,-5,GetDate())
SET @EndDate = GetDate()
SET NOCOUNT OFF
SELECT StateSummaryHistory.TagName, StartDateTime, EndDateTime, Value, vValue
 FROM StateSummaryHistory
 WHERE StateSummaryHistory.TagName IN ('VTIS01_FT04', 'VTIS01_TT344')
 AND wwVersion = 'Latest'
 AND wwRetrievalMode = 'Cyclic'
 AND wwCycleCount = 1
 AND StartDateTime >= @StartDate
 AND EndDateTime <= @EndDate

I needed to insert the data in a table already created so that I could do the select for the Report Builder, below is the code I am trying to insert in the table:

 INSERT INTO x_TagsDescr
 SELECT StateSummaryHistory.TagName, StartDateTime, EndDateTime, Value, vValue
 FROM StateSummaryHistory
 WHERE StateSummaryHistory.TagName IN ('VTIS01_FT04', 'VTIS01_TT344')

Returns the following error:

Column name or number of supplied values ​​does not match table definition.

x_TagsDescr is the table who I'm trying to insert.

Can anybody help me with this?

1

There are 1 answers

0
eshirvana On

its a good practice to mention column names when you insert to avoid this error:

 INSERT INTO x_TagsDescr (<list of column names that match columns in your select>)
 SELECT StateSummaryHistory.TagName, StartDateTime, EndDateTime, Value, vValue
 FROM StateSummaryHistory
 WHERE StateSummaryHistory.TagName IN ('VTIS01_FT04', 'VTIS01_TT344')