# SQL Select calculation

**URL:** <https://discourse.nodered.org/t/sql-select-calculation/12170>\
**Category:** General\
**Created:** [13 June 2019 08:15 UTC](https://discourse.nodered.org/t/sql-select-calculation/12170 "2019-06-13T08:15:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carloj](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Carloj](https://discourse.nodered.org/u/Carloj)\
**Post date:** [13 June 2019 08:15 UTC](https://discourse.nodered.org/t/sql-select-calculation/12170/1 "2019-06-13T08:15:33Z")

</div>

Im trying to select a calculation out of my database.

```auto
[{"id":"8db08aab.865c88","type":"mysql","z":"1f216cc0.281a93","mydb":"23c1ad96.82d712","name":"","x":550,"y":1400,"wires":[["8f679bb2.aa3e18"]]},{"id":"34d9ace1.488fa4","type":"function","z":"1f216cc0.281a93","name":"Select statement","func":"msg.topic = \"select concat(round(sum(case when data_soort='AAN' then data_waarde else null end)*100.0/sum(case when data_soort in ('AAN','UIT') then data_waarde else null end),2)) from IOT_DATA\";\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":1400,"wires":[["8db08aab.865c88"]]},{"id":"a47787ef.dd4958","type":"ui_gauge","z":"1f216cc0.281a93","name":"","group":"ef52ec43.10754","order":9,"width":0,"height":0,"gtype":"gage","title":"gauge","label":"units","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":970,"y":1380,"wires":[]},{"id":"4f278390.0987fc","type":"debug","z":"1f216cc0.281a93","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1010,"y":1440,"wires":[]},{"id":"d9c0977f.85dd48","type":"inject","z":"1f216cc0.281a93","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":100,"y":1400,"wires":[["34d9ace1.488fa4"]]},{"id":"8f679bb2.aa3e18","type":"function","z":"1f216cc0.281a93","name":"Select output","func":"if (msg.payload >0){\nreturn msg.topic;\n}\nreturn msg;","outputs":1,"noerr":0,"x":730,"y":1400,"wires":[["a47787ef.dd4958","4f278390.0987fc"]]},{"id":"23c1ad96.82d712","type":"MySQLdatabase","z":"","host":"127.0.0.1","port":"3306","db":"VEKO_IOT","tz":""},{"id":"ef52ec43.10754","type":"ui_group","z":"","name":"Pers 77","tab":"6b96da3f.ce1c04","order":1,"disp":true,"width":"24","collapse":false},{"id":"6b96da3f.ce1c04","type":"ui_tab","z":"","name":"Machine data","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

```

But it returns the full name with value. How can i get just the value?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [13 June 2019 08:28 UTC](https://discourse.nodered.org/t/sql-select-calculation/12170/2 "2019-06-13T08:28:34Z")

</div>

Show us what you get from the sql node (using a debug node) so we can more clearly understand the problem.

---

<div class="post-metadata">

**Author:** ![Carloj](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Carloj](https://discourse.nodered.org/u/Carloj)\
**Post date:** [13 June 2019 08:36 UTC](https://discourse.nodered.org/t/sql-select-calculation/12170/3 "2019-06-13T08:36:43Z")

</div>

```auto
concat(round(sum(case when data_soort='AAN' then data_waarde else null end)*100.0/sum(case when data_soort in ('AAN','UIT') then data_waarde else null end),2)): "98.50"

```

This the object i receive, but it should just "98.50"

![g](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/f8a213dc4138609da5ad47b35482b09efe8ee658.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [13 June 2019 12:35 UTC](https://discourse.nodered.org/t/sql-select-calculation/12170/4 "2019-06-13T12:35:46Z")

</div>

If you use

```auto
select concat(....) as 'value' from IOT_DATA

```

then the array element should be  
`{value: 98.5}`  
so you can access it by  
`msg.payload[0].value`  
The reason it returns an object is that if you said select a,b,c from... then you would need some way of knowing which was which. Because you did not provide an AS clause it has named it with the query string.
