# Mysql query set correct table name without ''

**URL:** <https://discourse.nodered.org/t/mysql-query-set-correct-table-name-without/48355>\
**Category:** General\
**Created:** [13 July 2021 11:32 UTC](https://discourse.nodered.org/t/mysql-query-set-correct-table-name-without/48355 "2021-07-13T11:32:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ketpa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ketpa/32/42496_2.png) [@ketpa](https://discourse.nodered.org/u/ketpa)\
**Post date:** [13 July 2021 11:32 UTC](https://discourse.nodered.org/t/mysql-query-set-correct-table-name-without/48355/1 "2021-07-13T11:32:11Z")

</div>

I want update mysql table  
Inside function:

msg.payload = ['harm', 'day', 'val', 1];  
msg.topic="UPDATE `?` SET `day`=?,`val`=? WHERE id=?" ;  
return msg;

How to put string 'harm' like `harm` not `'harm'` because it cause problem.

---

<div class="post-metadata">

**Author:** ![ScheepersJohan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scheepersjohan/32/39556_2.png) [@ScheepersJohan](https://discourse.nodered.org/u/ScheepersJohan)\
**Post date:** [13 July 2021 14:11 UTC](https://discourse.nodered.org/t/mysql-query-set-correct-table-name-without/48355/2 "2021-07-13T14:11:27Z")

</div>

I this what you need ? ''UPDATE dbname SET day= harm,val= day WHERE id=1"

```auto
[{"id":"1f9de5c0.4c944a","type":"tab","label":"Flow 11","disabled":false,"info":""},{"id":"375e9797.eb03b8","type":"inject","z":"1f9de5c0.4c944a","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\"harm\",\"day\",\"val\",1]","payloadType":"json","x":300,"y":180,"wires":[["ee484d8d.280f4","4765b696.56d1f8"]]},{"id":"ee484d8d.280f4","type":"function","z":"1f9de5c0.4c944a","name":"","func":"\nmsg.topic=\"UPDATE \" + msg.payload[0] + \" SET day= '\" + msg.payload[1] + \"',val= '\" + msg.payload[2] + \"' WHERE id=\" + msg.payload[3] + \";\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":240,"wires":[["30657752.7f00a8"]]},{"id":"30657752.7f00a8","type":"debug","z":"1f9de5c0.4c944a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":240,"wires":[]},{"id":"4765b696.56d1f8","type":"debug","z":"1f9de5c0.4c944a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":550,"y":180,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [13 July 2021 15:26 UTC](https://discourse.nodered.org/t/mysql-query-set-correct-table-name-without/48355/3 "2021-07-13T15:26:29Z")

</div>

I think my answer is probably identical to ScheepersJohan's.  
But **UPDATE 'harm' ...** should be OK. What error do you see?

```auto
[{"id":"c570f516.3cc1f","type":"function","z":"e97a564a.ba7478","name":"","func":"msg.topic=\"UPDATE \" \n+ msg.payload[0] \n+ \" SET day = '\" + msg.payload[1] +\"'\"\n+ \", val = '\" + msg.payload[2] +\"'\"\n+ \" WHERE id= '\" + msg.payload[3] +\"'\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":270,"y":160,"wires":[["c0ea3774.fefef"]]},{"id":"c0ea3774.fefef","type":"debug","z":"e97a564a.ba7478","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"topic","targetType":"msg","statusVal":"","statusType":"auto","x":440,"y":160,"wires":[]},{"id":"a24d5f2c.a7e96","type":"inject","z":"e97a564a.ba7478","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\"harm\", \"thursday\", \"next\", 1]","payloadType":"json","x":110,"y":160,"wires":[["c570f516.3cc1f"]]}]

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [11 September 2021 15:26 UTC](https://discourse.nodered.org/t/mysql-query-set-correct-table-name-without/48355/4 "2021-09-11T15:26:30Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
