Hello, I have a query where I am trying to select tags that are uploaded every second, on a 1 minute and 30 second interval. I have declared a start of current month and previous month as this will run once a month.
declare @FirstDayCurrentMonth datetime = DATEADD(mm, DATEDIFF(m,0,GETDATE()),0)
declare @FirstDayPreviousMonth datetime = DATEADD(mm, DATEDIFF(m,0,GETDATE())-1,0)
SELECT TOP (1000) DATEADD(MINUTE,1,FloatTable.[DateAndTime]) 'tags+1Min'
,FloatTable.[DateAndTime]
,FloatTable.[TagIndex]
,FloatTable.[Val]
,TagTable.[TagName]
,TagTable.[TagType]
,TagTable.[TagDataType]
FROM [FactoryTalk_Datalog].[dbo].[FloatTable] as FloatTable
JOIN [FactoryTalk_Datalog].[dbo].[TagTable] as TagTable
on FloatTable.[TagIndex] = TagTable.[TagIndex]
WHERE (TagTable.[TagName] = '[PLC]FI225'
OR TagTable.[TagName] = '[PLC]FI250'
OR TagTable.[TagName] = '[PLC]FI220'
OR TagTable.[TagName] = '[PLC]AT_FI510'
OR TagTable.[TagName] = '[PLC]AT_AI500'
OR TagTable.[TagName] = '[PLC]SS_FIT1109')
AND FloatTable.[DateAndTime] >= @FirstDayCurrentMonth
AND FloatTable.[DateAndTime] < @FirstDayPreviousMonth
What I have tried:
I have tried creating a new column with DateAdd() but it only adds the minute to the timestamp and does not increment. I have looked at other sources and videos but cannot figure out why I am having so much trouble outputting 30 second/1 minute intervals for selected tags.