我正在尝试从WonderWare历史数据库中获取数据库中所有标记的数据。已经有一个包含所有标记的表,所以我想使用子查询来选择所有标记名称。我在这个子查询中遇到错误。
我的sql声明:
/******
I want to be able to select:
- all columns
- for all tags <-- I'm getting an error here, trying to use a subquery
- between two time stamps
- at a specified resolution
******/
SELECT *
FROM
Runtime.[dbo].AnalogHistory
WHERE
TagName IN (
SELECT DISTINCT TagName
FROM
Runtime.dbo.Tag
)
AND
DateTime >= '2016-01-01 00:00'
AND
DateTime < '2016-01-01 00:30'
AND
wwResolution = 5000
AND
wwRetrievalMode = 'Average'
AND
wwTimeStampRule = 'Start'
我收到的错误如下:
OLE DB provider "INSQL" for linked server "INSQL" returned message "History queries must contain at least one valid tagname".
我猜这意味着它没有被正确执行。
我也尝试过使用openquery,但后来我得到了与子查询相关的其他错误,无法识别有关Tag表的'schema'信息:
OLE DB provider "INSQL" for linked server "INSQL" returned message "Failed to retrieve schema information for object 'Tag'".
这是改编的摘录:
TagName IN ( SELECT * FROM OPENQUERY(INSQL,
'SELECT DISTINCT TagName
FROM
Runtime.dbo.Tag')
)
答案 0 :(得分:2)
Historian Server不是普通的SQL Server数据库。它的历史视图从INSQL链接服务器获取数据。 INSQL有一些特殊规则,记录在HistorianConcepts.pdf中。
SELECT
*
FROM
Runtime.dbo.Tag t
INNER REMOTE JOIN
Runtime.dbo.AnalogHistory h
ON
t.TagName = h.TagName
WHERE
DateTime >= '2016-01-01 00:00'
AND
DateTime < '2016-01-01 00:30'
AND
wwResolution = 5000
AND
wwRetrievalMode = 'Average'
AND
wwTimeStampRule = 'Start'
答案 1 :(得分:0)
尝试:
SELECT DISTINCT aa.TagName FROM (
SELECT DateTime, TagName, Value
FROM History
WHERE DateTime >= '2016-01-01 00:00'
AND DateTime <= '2016-01-01 00:30'
AND wwResolution = 5000
AND wwRetrievalMode = 'Average'
AND wwTimeStampRule = 'Start'
) aa