# Moving tag history to new tag paths

**URL:** <https://forum.inductiveautomation.com/t/moving-tag-history-to-new-tag-paths/14010>\
**Category:** Ignition\
**Created:** [April 11, 2017, 9:30am UTC](https://forum.inductiveautomation.com/t/moving-tag-history-to-new-tag-paths/14010 "2017-04-11T09:30:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [April 11, 2017, 9:30am UTC](https://forum.inductiveautomation.com/t/moving-tag-history-to-new-tag-paths/14010/1 "2017-04-11T09:30:48Z")

</div>

Hi,

I need to move a large number of tags into a new folder structure, but I also need to keep the tag history as well.

I have mapped out the different history tables and how they interact with one another, and have tried to copy a small amount of history over to one renamed tag, however obviously there’s more to it than this this didn’t work. I presume it has something to do with how the created/retired and start/end dates work with the partitions and whatnot.

For a simple case of transferring a single tag’s history over for the last 3 months of data, how would I go about doing this?

Thanks in advance!  
Nick

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [April 11, 2017, 12:21pm UTC](https://forum.inductiveautomation.com/t/moving-tag-history-to-new-tag-paths/14010/2 "2017-04-11T12:21:16Z")

</div>

It seems that I can simply set the Created datetime field of the tag table (sqlt\_te) to be the earliest record’s t\_stamp value. The problem I’ve noticed though with the moved tag I’m testing with is that all data copied is quite slow to populate in the trend object (~2-7s depending on range)… When I compare it to the original tag, it’s almost instantaneous.

I used this query (it’s pretty horrid) to copy the old data for last march 2017, where ‘OLD TAG PATH’ and ‘NEW TAG PATH’ are not the real values I used:

```
INSERT INTO [dbo].[sqlt_data_1_2017_03]
SELECT
    tags.new_id as tagid
    ,[intvalue]
    ,[floatvalue]
    ,[stringvalue]
    ,[datevalue]
    ,[dataintegrity]
    ,[t_stamp]
FROM [sqlt_data_1_2017_03] data
INNER JOIN
    (
        SELECT
        tagnew.id as new_id
        ,tagold.id as old_id
        ,tagnew.tagpath as new_tagpath
        ,tagold.tagpath as old_tagpath
        FROM sqlth_te as tagold
        INNER JOIN
        sqlth_te as tagnew ON REPLACE(tagold.tagpath, 'OLD TAG PATH/', 'NEW TAG PATH/') = tagnew.tagpath
        WHERE tagnew.tagpath <> tagold.tagpath AND tagold.retired IS NULL AND tagnew.retired IS NULL
    ) as tags 
    ON tags.old_id = data.tagid
```
