Created
February 6, 2020 00:51
-
-
Save mrezekiel/d8e7dcdabb9501dca2b6cd7f02789344 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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