# MsSQL unique data Dropdown

**URL:** <https://discourse.nodered.org/t/mssql-unique-data-dropdown/49545>\
**Category:** General\
**Created:** [9 August 2021 20:13 UTC](https://discourse.nodered.org/t/mssql-unique-data-dropdown/49545 "2021-08-09T20:13:36Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![sefaguntepe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sefaguntepe/32/94497_2.png) [@sefaguntepe](https://discourse.nodered.org/u/sefaguntepe)\
**Post date:** [9 August 2021 20:13 UTC](https://discourse.nodered.org/t/mssql-unique-data-dropdown/49545/1 "2021-08-09T20:13:36Z")

</div>

I want to filter on date column in database. Then I want to show the sensor names that will come from here in the dropdown. (uniquely).

Here's what I can do

f1

```auto
start='2021-08-01'
end='2021-08-05'

msg.payload ="SELECT * FROM mat where date between '"+start+"' and '"+end+"';";
return msg;

```

* * *

f2

```auto
var newmsg = msg;
newmsg.options = [x];
var value;

for (var i = 0; i < msg.payload.length; i++) {
    //canal = msg.payload[i].address;
    value = msg.payload[i].sensor;
    newmsg.options[i] = {};
    newmsg.options[i] = value;

}

return msg;

```

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/3/532e4a689e02dd4f1194bd04c32f5e5ca110454e.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/5/d5c99ab114d44854f6e7dacedfec67da8ff4081f.png)

---

<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 August 2021 20:38 UTC](https://discourse.nodered.org/t/mssql-unique-data-dropdown/49545/2 "2021-08-09T20:38:24Z")

</div>

A better way to do this...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/a/0a7c5b4f2e49f9d8250216268daf01ac789146b5.png)

... this will negate an SQL injection and is easier to configure and understand.

PS, this uses node-red-contrib-mssql-plus which has many improvements and bug fixes over the 3y old node-red-contrib-mssql

---

<div class="post-metadata">

**Author:** ![rko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rko/32/45807_2.png) [@rko](https://discourse.nodered.org/u/rko)\
**Post date:** [9 August 2021 20:39 UTC](https://discourse.nodered.org/t/mssql-unique-data-dropdown/49545/3 "2021-08-09T20:39:33Z")

</div>

You could `group` everything with a SQL statement or transfer all data to Node-RED first and _filter_ it there. I would try to do it in SQL because then you're receiving only relevant data.

---

<div class="post-metadata">

**Author:** ![sefaguntepe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sefaguntepe/32/94497_2.png) [@sefaguntepe](https://discourse.nodered.org/u/sefaguntepe)\
**Post date:** [9 August 2021 20:39 UTC](https://discourse.nodered.org/t/mssql-unique-data-dropdown/49545/4 "2021-08-09T20:39:57Z")

</div>

do you think the data will be unique?

---

<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 August 2021 20:44 UTC](https://discourse.nodered.org/t/mssql-unique-data-dropdown/49545/5 "2021-08-09T20:44:15Z")

</div>

> [@sefaguntepe](#):
>
> do you think the data will be unique

Yes.

That's what `DISTINCT` is for.

You could also use `group by`

---

<div class="post-metadata">

**Author:** ![rko](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rko/32/45807_2.png) [@rko](https://discourse.nodered.org/u/rko)\
**Post date:** [9 August 2021 20:48 UTC](https://discourse.nodered.org/t/mssql-unique-data-dropdown/49545/6 "2021-08-09T20:48:18Z")

</div>

Can we see the above screenshot without your blue notes?

---

<div class="post-metadata">

**Author:** ![sefaguntepe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sefaguntepe/32/94497_2.png) [@sefaguntepe](https://discourse.nodered.org/u/sefaguntepe)\
**Post date:** [9 August 2021 20:54 UTC](https://discourse.nodered.org/t/mssql-unique-data-dropdown/49545/7 "2021-08-09T20:54:21Z")

</div>

thank you, it worked

---

<div class="post-metadata">

**Author:** ![sefaguntepe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sefaguntepe/32/94497_2.png) [@sefaguntepe](https://discourse.nodered.org/u/sefaguntepe)\
**Post date:** [9 August 2021 20:57 UTC](https://discourse.nodered.org/t/mssql-unique-data-dropdown/49545/8 "2021-08-09T20:57:56Z")

</div>

Is there a shortcut that I can print the number of data coming to the drop-down ?

---

<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 August 2021 20:59 UTC](https://discourse.nodered.org/t/mssql-unique-data-dropdown/49545/9 "2021-08-09T20:59:25Z")

</div>

what do you mean?

you mean a debug node to see what is going into the node?

---

<div class="post-metadata">

**Author:** ![sefaguntepe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sefaguntepe/32/94497_2.png) [@sefaguntepe](https://discourse.nodered.org/u/sefaguntepe)\
**Post date:** [9 August 2021 21:02 UTC](https://discourse.nodered.org/t/mssql-unique-data-dropdown/49545/10 "2021-08-09T21:02:07Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/7/67585c199a05462d6e2c89f84c40cfa1109937c6.png)

To print the number of data in the text box

---

<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 August 2021 21:38 UTC](https://discourse.nodered.org/t/mssql-unique-data-dropdown/49545/11 "2021-08-09T21:38:30Z")

</div>

> [@sefaguntepe](#):
>
> To print the number of data in the text box

what number, from where? from the database? as an index count?

---

<div class="post-metadata">

**Author:** ![sefaguntepe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sefaguntepe/32/94497_2.png) [@sefaguntepe](https://discourse.nodered.org/u/sefaguntepe)\
**Post date:** [10 August 2021 09:07 UTC](https://discourse.nodered.org/t/mssql-unique-data-dropdown/49545/12 "2021-08-10T09:07:50Z")

</div>

I want to count the number of data. As in the example, 8 pieces

---

<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:** [24 August 2021 09:08 UTC](https://discourse.nodered.org/t/mssql-unique-data-dropdown/49545/13 "2021-08-24T09:08:06Z")

</div>

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