# SQL Update query

**URL:** <https://forum.inductiveautomation.com/t/sql-update-query/8089>\
**Category:** Ignition\
**Created:** [March 3, 2014, 3:10pm UTC](https://forum.inductiveautomation.com/t/sql-update-query/8089 "2014-03-03T15:10:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![HALW80](https://avatars.discourse-cdn.com/v4/letter/h/47e85d/32.png) [@HALW80](https://forum.inductiveautomation.com/u/HALW80)\
**Post date:** [March 3, 2014, 3:10pm UTC](https://forum.inductiveautomation.com/t/sql-update-query/8089/1 "2014-03-03T15:10:01Z")

</div>

I have the follow script on a button:

date1= event.source.parent.getComponent(‘Label ddMMyyyy’).text  
site1 = str(‘CootehillWTW’)  
weather = str(event.source.parent.getComponent(‘Weather’).text)  
Elect\_Day = event.source.parent.getComponent(‘Elect Day’).floatValue  
Elect\_Night = event.source.parent.getComponent(‘Elect Night’).floatValue  
RW\_Flow = event.source.parent.getComponent(‘RW Flow’).floatValue  
BW\_Flow = event.source.parent.getComponent(‘BW Flow’).floatValue  
TW\_Flow = event.source.parent.getComponent(‘TW Flow’).floatValue  
Final\_Flow = event.source.parent.getComponent(‘Final Water Flow’).floatValue  
Flow\_Comment = event.source.parent.getComponent(‘Flow Comment’).text  
pH\_RW = event.source.parent.getComponent(‘ph RW’).floatValue  
pH = event.source.parent.getComponent(‘pH’).floatValue  
pH\_Final = event.source.parent.getComponent(‘pH Res Final Water’).floatValue  
Colour\_RW = event.source.parent.getComponent(‘Col RW’).floatValue  
Color\_Final = event.source.parent.getComponent(‘Col Final’).floatValue  
Turbidity\_RW = event.source.parent.getComponent(‘Turbidity RW’).floatValue  
Turbidity\_Final = event.source.parent.getComponent(‘Turbidity Final Water’).floatValue  
Free\_Res\_Chlor = event.source.parent.getComponent(‘Free Residual Chlorine’).floatValue  
Total\_Chlor = event.source.parent.getComponent(‘Total Chlorine’).floatValue  
Res\_Alum = event.source.parent.getComponent(‘Residual Alum’).floatValue  
Correct\_Alum = event.source.parent.getComponent(‘Corrected Alum’).floatValue  
Res\_Fluoride = event.source.parent.getComponent(‘Residual Fluoride’).floatValue  
Fluoride\_Consumed = event.source.parent.getComponent(‘Fluoride Consumed’).floatValue  
RW\_Manganese = event.source.parent.getComponent(‘Manganese RW’).floatValue  
Final\_Manganese = event.source.parent.getComponent(‘Manganese Final Water’).floatValue  
Lab\_Comment = event.source.parent.getComponent(‘Lab Comment’).text  
caretaker = event.source.parent.getComponent(‘Username’).text

ans = system.db.runPrepUpdate(“UPDATE REPORT\_WTW SET SiteName=?, Weather=?, Elect\_Day=?, Elect\_Night=?,RW\_Flow=?,BW\_Flow=?,TW\_Flow=?,Final\_Flow=?,Flow\_Comment=?,pH\_RW=?,pH=?,pH\_Final=?,Colour\_RW=?,Color\_Final=?,Turbidity\_RW=?,Turbidity\_Final=?,Free\_Residual\_Chlorine=?,Total\_Chlorine=?,Res\_Alum=?,Correct\_Alum=?,Res\_Fluoride=?,Fluoride\_Consumed=?,RW\_Manganese=?,Final\_Manganese=?,Lab\_Comment=?,Caretaker=? [color=#FF0000]WHERE DateofReport = ? [/color]”, [site1, weather,Elect\_Day,Elect\_Night,RW\_Flow,BW\_Flow,TW\_Flow,Final\_Flow,Flow\_Comment,pH\_RW,pH,pH\_Final,Colour\_RW,Color\_Final,Turbidity\_RW,Turbidity\_Final,Free\_Res\_Chlor,Total\_Chlor,Res\_Alum,Correct\_Alum,Res\_Fluoride,Fluoride\_Consumed,RW\_Manganese,Final\_Manganese,Lab\_Comment,caretaker,date1])

My query isn’t throwing up any errors yet doesn’t update the database. if I force WHERE DateofReport = ‘02-03-2014’ then it updates record ok

---

<div class="post-metadata">

**Author:** ![ISDProj](https://avatars.discourse-cdn.com/v4/letter/i/58956e/32.png) [@ISDProj](https://forum.inductiveautomation.com/u/ISDProj)\
**Post date:** [March 3, 2014, 9:07pm UTC](https://forum.inductiveautomation.com/t/sql-update-query/8089/2 "2014-03-03T21:07:39Z")

</div>

I’m guessing that the update not happening is because the date doesn’t exactly match.  
Without seeing the text in date1 I’m assuming you have it formatted as ddMMyyyy which would make it be interpreted as an integer i.e. 02-02-2014 =\> 2032014.  
Have you tried formatting the date as dd-MMM-yyyy ? I/We always use the short Month name format as SQL often attempts to convert dates to M/D/Y.  
Also you may need to wrap it in single-quotes if you are expecting a literal translation.  
e.g.

```auto
WHERE DateOfReport='?' 
```

---

<div class="post-metadata">

**Author:** ![greg.simpson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/greg.simpson/32/3135_2.png) [@greg.simpson](https://forum.inductiveautomation.com/u/greg.simpson)\
**Post date:** [April 21, 2014, 4:07pm UTC](https://forum.inductiveautomation.com/t/sql-update-query/8089/3 "2014-04-21T16:07:34Z")

</div>

emca\_user,

```
   Have you resolved your issue?
```
