简体   繁体   中英

Inserting data between SQL table and Wonderware Historian

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?

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM