# Get Column Name from Query

**URL:** <https://forum.inductiveautomation.com/t/get-column-name-from-query/6774>\
**Category:** Ignition\
**Created:** [June 26, 2013, 11:10pm UTC](https://forum.inductiveautomation.com/t/get-column-name-from-query/6774 "2013-06-26T23:10:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gadgetguru69](https://avatars.discourse-cdn.com/v4/letter/g/e274bd/32.png) [@gadgetguru69](https://forum.inductiveautomation.com/u/gadgetguru69)\
**Post date:** [June 26, 2013, 11:10pm UTC](https://forum.inductiveautomation.com/t/get-column-name-from-query/6774/1 "2013-06-26T23:10:48Z")

</div>

Wanted to see if anyone out there had easy way to do what I am trying to do. I am not sure but I may be missing something. I have query returing and I want to be able to read the columnnames and use them as the tag names to insert the value to the tags. But cant seam to figure out how of if I can read the column names. Any ideas?

`rs = system.db.runQuery("SELECT [equipment_value],Avg([milliseconds_cycle] / 1000)[Time_Cycle],Avg([angle_swing_out])[Swing_Angle]FROM [ACWSRV].[dbo].[data_dragline_cycle]WHERE [time_start] BETWEEN '2013/01/03' AND '2013/01/10'and equipment_value = 1 GROUP BY [equipment_value];")
for row in rs:
	for col in row:
		colName = str(col)
		print colName
		system.tag.writeToTag('AccuWeigh/8750/AW_Interface/'+colName+'/Value_This_Shift_AVG', col )`

---

<div class="post-metadata">

**Author:** ![Pat](https://avatars.discourse-cdn.com/v4/letter/p/8491ac/32.png) [@Pat](https://forum.inductiveautomation.com/u/Pat)\
**Post date:** [June 27, 2013, 4:56am UTC](https://forum.inductiveautomation.com/t/get-column-name-from-query/6774/2 "2013-06-27T04:56:58Z")

</div>

Convert your PyDataSet to a Dataset and then use getColumnName on the dataset? `rsDataset = system.dataset.toDataSet(rs)
colName = rsDataset.getColumnName(index)
`

---

<div class="post-metadata">

**Author:** ![gadgetguru69](https://avatars.discourse-cdn.com/v4/letter/g/e274bd/32.png) [@gadgetguru69](https://forum.inductiveautomation.com/u/gadgetguru69)\
**Post date:** [June 27, 2013, 2:20pm UTC](https://forum.inductiveautomation.com/t/get-column-name-from-query/6774/3 "2013-06-27T14:20:21Z")

</div>

Worked like a champ.

thanks Pat

This would be nice additions to the pyDataSet to be able to get the metadata getColumnName and getColumnLabel would be nice.
