MsSQL unique data Dropdown

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



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


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;


A better way to do this...

... 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

1 Like

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.

do you think the data will be unique?


That's what DISTINCT is for.

You could also use group by

Can we see the above screenshot without your blue notes?

thank you, it worked

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

what do you mean?

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

To print the number of data in the text box

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

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

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