Hello Team,
I’m trying to insert my query for plotting a graph as below but I getting this Error "mssql: Invalid column name ‘Time’.
declare @-consumptionTable table (RecordID int identity, TagName varchar(50), Time DateTime, Value_Daily decimal(22,2), consumptionValue decimal(22,2))
insert into @-consumptionTable (TagName, Time , Value_Daily)
SELECT TagName, DateTime, Value
FROM History
WHERE TagName IN (‘MWDashBoardIOs.C1_Co2’)
AND wwRetrievalMode = ‘Cyclic’
AND wwResolution = 86400000
AND wwQualityRule = ‘Extended’
AND wwVersion = ‘Latest’
AND $__timeFilter(Time) ORDER by 1
declare @-count int = (select count(1) from @-consumptionTable)
declare @-index int = 0
declare @-previousID int = 0
declare @-currentID int = 0
declare @-previousValue decimal (22,2)
declare @-currentValue decimal (22,2)
while (@index < @-count)
begin
if (@index = 0)
Begin
set @-currentID = (select top 1 recordID from @-consumptionTable)
set @-index = @-index + 1
continue;
End
set @-previousID = @-currentID
set @-currentID = (select recordID from @-consumptionTable where recordID = @-index-1)
set @-currentValue = (select isnull(Value_Daily, 0) from @-consumptionTable where RecordID = @-currentID)
set @-previousValue = (select isnull(Value_Daily, 0) from @-consumptionTable where RecordID = @-previousID)
update @-consumptionTable set consumptionValue = @-currentValue - @-previousValue where RecordID = @-previousID
set @-index = @-index + 1
end
select * from @-consumptionTable
Note >> I Replaced @ by “@-”