Skip to content

Instantly share code, notes, and snippets.

@mrezekiel
Created February 6, 2020 00:51
Show Gist options
  • Save mrezekiel/d8e7dcdabb9501dca2b6cd7f02789344 to your computer and use it in GitHub Desktop.
Save mrezekiel/d8e7dcdabb9501dca2b6cd7f02789344 to your computer and use it in GitHub Desktop.
DECLARE @StartDate DateTime
DECLARE @EndDate DateTime
DECLARE @iArea INT
DECLARE @sTagName NVARCHAR(50)
SET @StartDate = '19700101 0:00'
SET @EndDate = GETDATE()
/* Get TagName from ID, Historian requires TagName for lookups */
SELECT @sTagName = (SELECT tr.TagName
FROM TagRef tr
WHERE tr.wwDomainTagKey = @iArea)
/* Get all batch strings for TagName */
SELECT h.vValue AS SampleValue
FROM History h
WHERE h.TagName IN (@sTagName)
AND NULLIF(h.vValue, '') IS NOT NULL
AND h.QualityDetail = 192
AND h.DateTime >= @StartDate
AND h.DateTime <= @EndDate
AND h.wwRetrievalMode = 'Full'
AND h.wwQualityRule = 'Extended'
AND h.wwVersion = 'Latest'
ORDER BY SampleValue DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment