我在 MSSQL 2008 中有以下 sql 语句。
use gasnominations
INSERT INTO dbo.GasData (readDate,TagName,Value, amendedValue)
with emptce as
(SELECT timestamp AS Interval, Left(Right(TagName,Len(TagName)-5),Len(TagName)-10) as TagName,
CONVERT(decimal(10, 3), ROUND(value, 3)) As Value
FROM
OPENQUERY(IHISTORIAN,'
SET starttime =''yesterday +6h'', endtime =''today +6h''
SELECT timestamp, tagname, value
FROM ihRawData
WHERE tagname = "UMIS.99FC9051.F_CV"
OR tagname = "UMIS.99F851C.F_CV"
OR tagname = "UMIS.35GTGAS.F_CV"
OR tagname = "UMIS.35HRSGGAS.F_CV"
OR tagname = "UMIS.99XXG546.F_CV"
OR tagname = "UMIS.99XXG547.F_CV"
OR tagname = "UMIS.99F9082.F_CV"
OR tagname = "UMIS.99FC20107.F_CV"
OR tagname = "UMIS.95FIQ5043.F_CV"
OR tagname = "UMIS.99PBGAS.F_CV"
OR tagname = "UMIS.99FE1100.F_CV"
OR tagname = "UMIS.99FE1200.F_CV"
OR tagname = "UMIS.99FC8279.F_CV"
OR tagname = "UMIS.35FI8316.F_CV"
AND timestamp BETWEEN ''timestamp'' and ''timestamp''
AND SamplingMode =Calculated
AND CalculationMode =Average
AND IntervalMilliseconds =1h
ORDER BY tagname, timestamp'))
select emptce.Interval, emptce.TagName, emptce.Value, gasdata.amendedValue from emptce inner join gasdata on emptce.TagName = gasData.tagName COLLATE DATABASE_DEFAULT
and emptce.Interval = DATEADD(DAY, 1, readDate)
我收到以下错误“如果此语句是公用表表达式、xmlnamespaces 子句或更改跟踪上下文子句,则前一个语句必须以分号终止。”
我曾尝试在 with 之前添加一个分号,但它只是在 ; 上出现错误。