I want to create a stored procedure that queries for all the tags in Historian that contain a specific string in the name such as "#PV", belong to a specific Area and also currently exist in the IDE.
I am using the "dbo._Tag" table and "dbo._TagExtendedProperty" table, but both these tables return all the historical tags including the deleted tags. I only want currently existing tags. I thought of using the "dbo.History" table with "QualityDetail" property set to "Good" but this table needs the tag names as parameters to work and so I can't use it to get all tags with contains a specific string like "#PV".
This is the query I am currently using:
SELECT [TagName] as Tag,
[TagExtendedPropertyKey],
[PropertyNameKey],
CAST([PropertyValue] AS NVARCHAR) as AreaLocation,
[ChangeVersion]
FROM [Runtime].[dbo].[_TagExtendedProperty]
WHERE [TagName] LIKE ''%Ai1Scaled#PV''
AND [PropertyNameKey] = ''3'') AS datasource
WHERE [AreaLocation] LIKE ''%' + @Areaname + '%''