# Returnvalue of MSSQL Query Select Count

**URL:** <https://discourse.nodered.org/t/returnvalue-of-mssql-query-select-count/54933>\
**Category:** General\
**Tags:** database\
**Created:** [9 December 2021 13:59 UTC](https://discourse.nodered.org/t/returnvalue-of-mssql-query-select-count/54933 "2021-12-09T13:59:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Riggi](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@Riggi](https://discourse.nodered.org/u/Riggi)\
**Post date:** [9 December 2021 13:59 UTC](https://discourse.nodered.org/t/returnvalue-of-mssql-query-select-count/54933/1 "2021-12-09T13:59:07Z")

</div>

Hello, I'm using the node-red-contrib-mssql-plus  
Everthing works well!  
One thing is strange and Im struggeling ;(  
The Returnvalue of the command Select Count returns the right Value but I can't use the returnvalue. The debugmessage shows the following:  
9.12.2021, 14:48:52node: 8c733af0095bc140  
site1 : msg.payload : array[1]  
array[1]  
0: object  
499999  
I cant view this Value 499999 in the dashboard. There allways appear: [{"":499999}]

Where is my mistake?  
Thnaks in Advance

---

<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:** [9 December 2021 14:13 UTC](https://discourse.nodered.org/t/returnvalue-of-mssql-query-select-count/54933/2 "2021-12-09T14:13:25Z")

</div>

You need to tell the dashboard node that the value is in msg.payload[0], so in the Value Format field put `{{msg.payload[0]}}`

---

<div class="post-metadata">

**Author:** ![Riggi](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@Riggi](https://discourse.nodered.org/u/Riggi)\
**Post date:** [9 December 2021 14:38 UTC](https://discourse.nodered.org/t/returnvalue-of-mssql-query-select-count/54933/3 "2021-12-09T14:38:02Z")

</div>

If have try'd this also with the same Result!  
If I use your suggestion in the debug window it shows:  
9.12.2021, 15:36:37node: 8c733af0095bc140  
site1 : msg.msg.payload[0] : Object  
object  
499999

---

<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:** [9 December 2021 15:00 UTC](https://discourse.nodered.org/t/returnvalue-of-mssql-query-select-count/54933/4 "2021-12-09T15:00:12Z")

</div>

Ah, I see the 499999 is an object somehow. Feed it through a JSON node and then to a debug node and show us what it says.

---

<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:** [9 December 2021 15:15 UTC](https://discourse.nodered.org/t/returnvalue-of-mssql-query-select-count/54933/5 "2021-12-09T15:15:37Z")

</div>

> [@Riggi](#):
>
> in the dashboard. There allways appear: [{"":499999}]

Actually, that tells us the answer. The element is an object with an empty key name (or unprintable character). In a function node you can use something like

```auto
msg.payload = Object.entries(msg.payload[0])[0][1]
return msg;

```

which returns the value of the first key in the object in the first element of msg.payload.  
Why the node gives you such a bizarre return is beyond me.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [9 December 2021 16:53 UTC](https://discourse.nodered.org/t/returnvalue-of-mssql-query-select-count/54933/6 "2021-12-09T16:53:56Z")

</div>

The results of a query to MSSQL is array of objects where the property names are the field names.

Try changing your query to something like `select count(*) as RowCount from myTable`

Also, instead of selecting text in the debug panel, please use the `copy value` button that appears under your mouse cursor when you hover over the payload in the debug window. And please use the code button when pasting code/data into the forum.

* * *

Canned replies...

* * *

#### Canned reply 1...

in order to make code more readable and importable it is important to surround your code with three backticks  
`````  
`like this`  
`````

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

#### Canned reply 2...

There’s a great page in the docs that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

> **[Working with messages : Node-RED](https://nodered.org/docs/user-guide/messages)**

---

<div class="post-metadata">

**Author:** ![Riggi](https://avatars.discourse-cdn.com/v4/letter/r/278dde/32.png) [@Riggi](https://discourse.nodered.org/u/Riggi)\
**Post date:** [9 December 2021 19:05 UTC](https://discourse.nodered.org/t/returnvalue-of-mssql-query-select-count/54933/7 "2021-12-09T19:05:12Z")

</div>

Thanks, the hint with  
''' `as RowCount`''' was very helpfull, now the object Name is defined and i can read out the value of RowCount  
Thank you verry much!!!

---

<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:** [23 December 2021 19:05 UTC](https://discourse.nodered.org/t/returnvalue-of-mssql-query-select-count/54933/8 "2021-12-23T19:05:32Z")

</div>

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