# Inserting tag data into a database

**URL:** <https://forum.inductiveautomation.com/t/inserting-tag-data-into-a-database/72260>\
**Category:** Ignition\
**Created:** [April 10, 2023, 2:07pm UTC](https://forum.inductiveautomation.com/t/inserting-tag-data-into-a-database/72260 "2023-04-10T14:07:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan\_mueller](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@dan\_mueller](https://forum.inductiveautomation.com/u/dan_mueller)\
**Post date:** [April 10, 2023, 2:07pm UTC](https://forum.inductiveautomation.com/t/inserting-tag-data-into-a-database/72260/1 "2023-04-10T14:07:26Z")

</div>

How can I write tag data to a database. Not sure how to setup parameters. Query below works with sample data but I want to use tag data

Insert into HWS\_Status  
(part\_number,line\_running,record)  
values  
('CC3400','yes','1') – using this as a test value…….

---

<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:** [April 10, 2023, 2:14pm UTC](https://forum.inductiveautomation.com/t/inserting-tag-data-into-a-database/72260/2 "2023-04-10T14:14:31Z")

</div>

Read the tag values with `system.tag.readBlocking()`. Extract the list of values from the returned list of `QualifiedValue`s. Supply them as parameters in a call to `system.db.runPrepUpdate()`. Something like this:

```auto
tagPaths = ["[default]path/to/folder/%s" % tagname for tagname in ['PN', 'LR', 'REC']]
insertSQL = """
Insert into HWS_Status (part_number, line_running, record)
Values (?, ?, ?)"""

def doInsert():
	pn, lr, rec = [x.value for x in system.tag.readBlocking(tagPaths)]
	rows_inserted = system.db.runPrepUpdate(insertSQL, [pn, lr, rec], 'MyDatasourceName')
	return rows_inserted

```

---

<div class="post-metadata">

**Author:** ![dan\_mueller](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@dan\_mueller](https://forum.inductiveautomation.com/u/dan_mueller)\
**Post date:** [April 10, 2023, 3:12pm UTC](https://forum.inductiveautomation.com/t/inserting-tag-data-into-a-database/72260/3 "2023-04-10T15:12:39Z")

</div>

Thanks Phil. Do you know of an example for this or some online help? I would like to understand how this scripting works. I am new to ignition with no sql background

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [April 10, 2023, 3:17pm UTC](https://forum.inductiveautomation.com/t/inserting-tag-data-into-a-database/72260/4 "2023-04-10T15:17:11Z")

</div>

I highly recommend taking the Inductive University course, they go over all the main points of using Ignition [https://inductiveuniversity.com/](https://inductiveuniversity.com/)
