How/where do I find the tagid of a tag in (vision 7.9)?

I am using this query in the report using script (vision 7.9)
SELECT top 1 floatvalue, t_stamp FROM sqlt_data_1_2024_08 where tagid = 1735 order by t_stamp desc
and I only see the data until August 28th even though the tag is working and shows the trend now.

Also how do I find the tagid for that tag? I think that would help me to update the query.

Why are you trying to obtain a specific tagid? What's the actual thing you're trying to do?

You can manually reconstruct the logic the historian uses internally, by querying across a series of tables:

It's not a good idea, generally.

1 Like

There is a old script in the report (not created by me) that uses above query where tagid = 1735 and some other numbers.
For some reason it is not showing the data after Aug 28th.

Also, I found the table sqlth_te and wanted to see if it changed the tagid or something happened to the tag.

Any time anything related to the History settings on the tag are changed, the record in sqlth_te is retired and a new record with a new ID is created for that tag.
Also depending on the partitioning in the DB, your source table will change as well.
You are much better off using built in tag history query tools to get the data.

2 Likes

As suspected, it says retired on 2024-8-28 09:58:44. I searched for the tags in that table and updated the tagid and it is working now.
I am not sure what happened, but someone updated something to those tags as the old tagid was retired and created new tagid.

well you can always join the sqlth_te table and then use the tag PATH for the query instead of the ID.

SELECT        
TOP (1) floatvalue,t_stamp
FROM LatestTagPartitionTable
INNER JOIN
sqlth_te ON LatestTagPartitionTable.tagid = sqlth_te.id
WHERE
(sqlth_te.tagpath = 'Path/To/Actual/Tag') AND sqlth_te.retired IS NULL

The above should work for MS SQL, off the top of my head.
Replace LatestTagPartitionTable and Path/To/Actual/Tag with your values.

Again though, if you use the built in tag history tools, you won't have to worry about retired and what table to pull from. It will UNION the old tagid with any new ones.

1 Like

Thanks, that's what I am doing next. Using Query-Tag History to do the same thing in the script and avoid using tagid.

2 Likes