# Can I tie the database name in a tag based script to a memory tag value?

**URL:** <https://forum.inductiveautomation.com/t/can-i-tie-the-database-name-in-a-tag-based-script-to-a-memory-tag-value/64558>\
**Category:** Ignition\
**Created:** [September 27, 2022, 5:56pm UTC](https://forum.inductiveautomation.com/t/can-i-tie-the-database-name-in-a-tag-based-script-to-a-memory-tag-value/64558 "2022-09-27T17:56:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neil\_Carty](https://avatars.discourse-cdn.com/v4/letter/n/90ced4/32.png) [@Neil\_Carty](https://forum.inductiveautomation.com/u/Neil_Carty)\
**Post date:** [September 27, 2022, 5:56pm UTC](https://forum.inductiveautomation.com/t/can-i-tie-the-database-name-in-a-tag-based-script-to-a-memory-tag-value/64558/1 "2022-09-27T17:56:57Z")

</div>

Hello. I am currently using 8.1.17 and am using tag event scripts to write to my database. IT has informed me that we will be changing over our database with a newer one and the tables that I am currently writting to will be changed. Can i try my database name to a memory tag and use it as a variable in my update? In the script below i would like to change “Epics” to the dbConn that i have marked out in my variable list. I have tried but cannt get it to work. Any help would be greatly appreciated.

def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):  
“”"  
Fired whenever the current value changes in value or quality.

```
Arguments:
	tag: The source tag object. A read-only wrapper for obtaining tag
	     properties.
	tagPath: The full path to the tag (String)
	previousValue: The previous value. This is a "qualified value", so it
	               has value, quality, and timestamp properties.
	currentValue: The current value. This is a "qualified value", so it has
	              value, quality, and timestamp properties.
	initialChange: A boolean flag indicating whether this event is due to
	               the first execution or initial subscription.
	missedEvents: A flag indicating that some events have been skipped due
	              to event overflow.
"""
if previousValue.value != currentValue.value and initialChange == False:
	plant = system.tag.read("[default]CRP Checklist/QueryBuilingTags/Plant").value
Furnace =system.tag.read("[default]CRP Checklist/QueryBuilingTags/Furnace").value
line = system.tag.read("[default]CRP Checklist/QueryBuilingTags/Line").value
CheckListName = system.tag.read("[default]CRP Checklist/QueryBuilingTags/CheckListName").value
TagName = system.tag.read("[default]CRP Checklist/PCheck2Value.Name").value
TagValue = system.tag.read("[default]CRP Checklist/PCheck2Value").value
TagDataType = system.tag.read("[default]CRP Checklist/QueryBuilingTags/TagDataType").value
DateEntered = system.tag.read("[default]CRP Checklist/QueryBuilingTags/DateEntered").value
ScheduledTime = system.tag.read("[default]CRP Checklist/PCheck2Time").value
ActualTime = system.tag.read("[default]CRP Checklist/PCheck2Value.Timestamp").value
#bdConn = System.tag.read("[default]CRP Checklist/QueryBuilingTags/Database").value

system.db.runPrepUpdate("INSERT INTO foy.SCM_Checklist (PlantID, Furnace, Line, CheckListName, TagName, TagValue, TagDataType, DateEntered, ScheduledTime, ActualTime) VALUES (?,?,?,?,?,?,?,?,?,?)",[plant, Furnace, line, CheckListName, TagName, TagValue, TagDataType, DateEntered, ScheduledTime, ActualTime],"Epics")

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [September 27, 2022, 6:30pm UTC](https://forum.inductiveautomation.com/t/can-i-tie-the-database-name-in-a-tag-based-script-to-a-memory-tag-value/64558/2 "2022-09-27T18:30:38Z")

</div>

What have you tried?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 27, 2022, 6:33pm UTC](https://forum.inductiveautomation.com/t/can-i-tie-the-database-name-in-a-tag-based-script-to-a-memory-tag-value/64558/3 "2022-09-27T18:33:58Z")

</div>

_Pssst! Please edit your post to format your script._

Click the pencil to edit, then use your mouse to select everything from the `def` to the end of your script, then click the “preformatted text” button, that looks like this: **\</\>**.

---

<div class="post-metadata">

**Author:** ![Neil\_Carty](https://avatars.discourse-cdn.com/v4/letter/n/90ced4/32.png) [@Neil\_Carty](https://forum.inductiveautomation.com/u/Neil_Carty)\
**Post date:** [September 27, 2022, 7:16pm UTC](https://forum.inductiveautomation.com/t/can-i-tie-the-database-name-in-a-tag-based-script-to-a-memory-tag-value/64558/4 "2022-09-27T19:16:08Z")

</div>

Typo… working now. Thank you though guys.
