【问题标题】:Inserting data between SQL table and Wonderware Historian在 SQL 表和 Wonderware Historian 之间插入数据
【发布时间】:2026-02-04 00:50:02
【问题描述】:

我正在尝试从 Wonderware Historian 获取值以在报表生成器中读取。我通过 Historian Client Query 获得了下面的 SQL 代码,但此代码直接从 SQL 视图中进行选择。

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

我需要在已经创建的表中插入数据,以便我可以为报表生成器进行选择,下面是我试图在表中插入的代码:

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

返回以下错误:

提供的值的列名或数量与表定义不匹配。

x_TagsDescr 是我要插入的表。

谁能帮我解决这个问题?

【问题讨论】:

    标签: sql sql-server reportbuilder wonderware historian


    【解决方案1】:

    在插入时提及列名以避免此错误是一个好习惯:

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

    【讨论】: