# Dynamic MS SQL Query Chart

**URL:** <https://discourse.nodered.org/t/dynamic-ms-sql-query-chart/71525>\
**Category:** Industrial\
**Tags:** database, chart, dashboard\
**Created:** [30 November 2022 22:19 UTC](https://discourse.nodered.org/t/dynamic-ms-sql-query-chart/71525 "2022-11-30T22:19:10Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ardukus](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@ardukus](https://discourse.nodered.org/u/ardukus)\
**Post date:** [30 November 2022 22:19 UTC](https://discourse.nodered.org/t/dynamic-ms-sql-query-chart/71525/1 "2022-11-30T22:19:10Z")

</div>

Hi all,  
this is my second topic.  
I started with a project a few days ago. Thanks to the help of kind people in this forum I was able to implement some features in the project.  
Here you can find the beginning of the story:  
[First Post](https://discourse.nodered.org/t/read-accelerometer-values-and-store-them-in-sql-server/71258)

A few learnings later I am facing a new problem where I cant get my head around.  
What I have so far:  
I write accelerometer values from a modbus-device into an mssql db.  
I can parse the table content into a line chart

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/7/87ef7fd691ddf68fd0b5f772c09308f6d6d4d86f.png)

Using the following flow:

```auto
[
    {
        "id": "f5c107a16d194936",
        "type": "inject",
        "z": "4e100d14e53b3afc",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 120,
        "y": 540,
        "wires": [
            [
                "8c2ee81a9259c669"
            ]
        ]
    },
    {
        "id": "a4e8711562181b92",
        "type": "function",
        "z": "4e100d14e53b3afc",
        "name": "function 3",
        "func": "//var data = [[{\"x\":1537348236000,\"y\":2493},{\"x\":1537348326000,\"y\":2493}]];\n//\nvar series = [\"timestamp\", \"IMUValues\"];\nvar labels = [\"Labels\"];\nvar data = [];\n\nvar i, len; //string; string = \"\";\n\nfor (i = 1, len = msg.payload.length; i < len; i++) {\n\n var thetime = Date.parse(msg.payload[i].timestamp);\n var thevalue = Number(msg.payload[i].IMUValue);\n\n data.push({x: thetime, y: thevalue});\n\n //data.push({ \"x\": Date.parse(msg.payload[i].timestamp) + 2 * 60 * 60, \"y\": Number(msg.payload[i].IMUValue) / 100 });\n}\n\ndata = [data];\n\nmsg.payload = [{ series, data, labels }];\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 600,
        "y": 540,
        "wires": [
            [
                "e13660ec95d6c4f1"
            ]
        ]
    },
    {
        "id": "e13660ec95d6c4f1",
        "type": "ui_chart",
        "z": "4e100d14e53b3afc",
        "name": "",
        "group": "54831fc8fbeb93e3",
        "order": 0,
        "width": "6",
        "height": "16",
        "label": "Acceleration Values",
        "chartType": "line",
        "legend": "false",
        "xformat": "HH:mm:ss",
        "interpolate": "bezier",
        "nodata": "",
        "dot": true,
        "ymin": "",
        "ymax": "",
        "removeOlder": 1,
        "removeOlderPoints": "",
        "removeOlderUnit": "3600",
        "cutout": 0,
        "useOneColor": false,
        "useUTC": false,
        "colors": [
            "#1f77b4",
            "#aec7e8",
            "#f77502",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "outputs": 1,
        "useDifferentColor": false,
        "className": "",
        "x": 830,
        "y": 540,
        "wires": [
            []
        ]
    },
    {
        "id": "8c2ee81a9259c669",
        "type": "MSSQL",
        "z": "4e100d14e53b3afc",
        "mssqlCN": "5558b0cd5f739949",
        "name": "",
        "outField": "payload",
        "returnType": 0,
        "throwErrors": 1,
        "query": "SELECT timestamp, IMUValue \r\nFROM t_test\r\nWHERE meassurementID = 3\r\nORDER BY timestamp \r\n ",
        "modeOpt": "queryMode",
        "modeOptType": "query",
        "queryOpt": "payload",
        "queryOptType": "editor",
        "paramsOpt": "",
        "paramsOptType": "editor",
        "rows": "rows",
        "rowsType": "msg",
        "params": [
            {
                "output": false,
                "name": "ID",
                "type": "int",
                "valueType": "msg",
                "value": "ID",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            }
        ],
        "x": 340,
        "y": 540,
        "wires": [
            [
                "a4e8711562181b92"
            ]
        ]
    },
    {
        "id": "54831fc8fbeb93e3",
        "type": "ui_group",
        "name": "Standard",
        "tab": "48c6c05b20fdbbaf",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "5558b0cd5f739949",
        "type": "MSSQL-CN",
        "tdsVersion": "7_4",
        "name": "",
        "server": "localhost",
        "port": "1433",
        "encyption": true,
        "trustServerCertificate": true,
        "database": "Node_Red_TestDB",
        "useUTC": true,
        "connectTimeout": "15000",
        "requestTimeout": "15000",
        "cancelTimeout": "5000",
        "pool": "5",
        "parseJSON": false,
        "enableArithAbort": true
    },
    {
        "id": "48c6c05b20fdbbaf",
        "type": "ui_tab",
        "name": "Home",
        "icon": "home",
        "disabled": false,
        "hidden": false
    }
]

```

The query actually pics the readings with a certain ID

```auto
SELECT timestamp, IMUValue 
FROM t_test
WHERE meassurementID = 3
ORDER BY timestamp 
  

```

What I am now trying to do is to make the chart changing dynamically acording to a numeric control:

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/9/9907cbf4a886efbc57d85e75bf30c165a02299aa.png)

My approach is to hand over the ID to the mssql node but I dont get any values then, the chart is staying empty.

Debug 7 outout:

```auto
{"payload":[],"socketid":"jnCGJBUvAZZ2HWCWAAAR","_msgid":"c5b10456bf18d77b","query":"SELECT timestamp, IMUValue \r\nFROM t_test\r\nWHERE meassurementID = @ID\r\nORDER BY timestamp \r\n ","queryMode":"query","queryParams":[{"output":false,"name":"ID","type":{},"options":{"nullable":true,"primary":false,"identity":false,"readOnly":false}}],"sqlInfo":[]}

```

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

---

<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:** [1 December 2022 13:37 UTC](https://discourse.nodered.org/t/dynamic-ms-sql-query-chart/71525/2 "2022-12-01T13:37:38Z")

</div>

> [@ardukus](#):
>
> Debug 7 outout:

If this is the output of the MSSQL-PLUS, only the query is retuned, no data.

Are you sure the data is in the table?

---

<div class="post-metadata">

**Author:** ![ardukus](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@ardukus](https://discourse.nodered.org/u/ardukus)\
**Post date:** [1 December 2022 17:51 UTC](https://discourse.nodered.org/t/dynamic-ms-sql-query-chart/71525/3 "2022-12-01T17:51:56Z")

</div>

yes an I dont get why.  
When I query against the db I get my values as expected

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/3/13ad25cb9050502943a0804517958f8dcc44fb3b.png)

What I hand over to the SQL Node is  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/6/b66c83d9c4c3b2a737dfb5c0504d61598d357563.png)

```auto
{"payload":2,"socketid":"neJQqvCW37M0sDWTAAAB","_msgid":"4d3e33c4e97630ba"}

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [1 December 2022 18:18 UTC](https://discourse.nodered.org/t/dynamic-ms-sql-query-chart/71525/4 "2022-12-01T18:18:50Z")

</div>

After Measurement ID use a change node and  
set `msg.` `payload.ID`  
to `msg.` `payload`

I don't use the mssql nodes but the read me seems to suggest that @ID needs to me in msg.payload.ID.

---

<div class="post-metadata">

**Author:** ![ardukus](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@ardukus](https://discourse.nodered.org/u/ardukus)\
**Post date:** [2 December 2022 18:59 UTC](https://discourse.nodered.org/t/dynamic-ms-sql-query-chart/71525/5 "2022-12-02T18:59:01Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/7/2701976f80ee00c164e04240e3883c5a92b794ee.png)

I was able to fix it by using the template node. Now the charts are "dynamic".

```auto
[
    {
        "id": "e13660ec95d6c4f1",
        "type": "ui_chart",
        "z": "4e100d14e53b3afc",
        "name": "",
        "group": "94e907ca56e3b24e",
        "order": 0,
        "width": "6",
        "height": "16",
        "label": "Acceleration Values",
        "chartType": "line",
        "legend": "false",
        "xformat": "HH:MM:SSSS",
        "interpolate": "bezier",
        "nodata": "",
        "dot": true,
        "ymin": "",
        "ymax": "",
        "removeOlder": 1,
        "removeOlderPoints": "",
        "removeOlderUnit": "3600",
        "cutout": 0,
        "useOneColor": false,
        "useUTC": false,
        "colors": [
            "#1f77b4",
            "#aec7e8",
            "#f77502",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "outputs": 1,
        "useDifferentColor": false,
        "className": "",
        "x": 970,
        "y": 480,
        "wires": [
            []
        ]
    },
    {
        "id": "d195a6024399b10c",
        "type": "ui_numeric",
        "z": "4e100d14e53b3afc",
        "name": "",
        "label": "Meassurement ID",
        "tooltip": "",
        "group": "94e907ca56e3b24e",
        "order": 1,
        "width": "2",
        "height": "2",
        "wrap": false,
        "passthru": false,
        "topic": "payload",
        "topicType": "msg",
        "format": "{{msg.payload}}",
        "min": "1",
        "max": "999",
        "step": 1,
        "className": "",
        "x": 150,
        "y": 480,
        "wires": [
            [
                "cc99de36f155f64e"
            ]
        ]
    },
    {
        "id": "cc99de36f155f64e",
        "type": "template",
        "z": "4e100d14e53b3afc",
        "name": "",
        "field": "payload",
        "fieldType": "msg",
        "format": "handlebars",
        "syntax": "mustache",
        "template": "SELECT timestamp, IMUValue FROM t_test WHERE meassurementID = {{payload}}\n\n\n\n\n\n\n\n",
        "output": "str",
        "x": 360,
        "y": 480,
        "wires": [
            [
                "67a7fb535c9ce43d"
            ]
        ]
    },
    {
        "id": "67a7fb535c9ce43d",
        "type": "MSSQL",
        "z": "4e100d14e53b3afc",
        "mssqlCN": "5558b0cd5f739949",
        "name": "",
        "outField": "payload",
        "returnType": 0,
        "throwErrors": 1,
        "query": "SELECT timestamp, IMUValue \r\nFROM t_test\r\nWHERE meassurementID = @ID\r\nORDER BY timestamp \r\n ",
        "modeOpt": "queryMode",
        "modeOptType": "query",
        "queryOpt": "payload",
        "queryOptType": "msg",
        "paramsOpt": "",
        "paramsOptType": "editor",
        "rows": "rows",
        "rowsType": "msg",
        "params": [],
        "x": 560,
        "y": 480,
        "wires": [
            [
                "ea7695f47ed3dfbc"
            ]
        ]
    },
    {
        "id": "ea7695f47ed3dfbc",
        "type": "function",
        "z": "4e100d14e53b3afc",
        "name": "function 6",
        "func": "//var data = [[{\"x\":1537348236000,\"y\":2493},{\"x\":1537348326000,\"y\":2493}]];\n//\nvar series = [\"timestamp\", \"IMUValues\"];\nvar labels = [\"Labels\"];\nvar data = [];\n\nvar i, len; //string; string = \"\";\n\nfor (i = 1, len = msg.payload.length; i < len; i++) {\n\n var thetime = Date.parse(msg.payload[i].timestamp);\n var thevalue = Number(msg.payload[i].IMUValue);\n\n data.push({x: thetime, y: thevalue});\n\n //data.push({ \"x\": Date.parse(msg.payload[i].timestamp) + 2 * 60 * 60, \"y\": Number(msg.payload[i].IMUValue) / 100 });\n}\n\ndata = [data];\n\nmsg.payload = [{ series, data, labels }];\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 760,
        "y": 480,
        "wires": [
            [
                "e13660ec95d6c4f1"
            ]
        ]
    },
    {
        "id": "94e907ca56e3b24e",
        "type": "ui_group",
        "name": "Diisplay Meassurments",
        "tab": "72dd0e176fbce39f",
        "order": 2,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "5558b0cd5f739949",
        "type": "MSSQL-CN",
        "tdsVersion": "7_4",
        "name": "",
        "server": "localhost",
        "port": "1433",
        "encyption": true,
        "trustServerCertificate": true,
        "database": "Node_Red_TestDB",
        "useUTC": true,
        "connectTimeout": "15000",
        "requestTimeout": "15000",
        "cancelTimeout": "5000",
        "pool": "5",
        "parseJSON": false,
        "enableArithAbort": true
    },
    {
        "id": "72dd0e176fbce39f",
        "type": "ui_tab",
        "name": "Create new meassurement",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]

```

And always the same^^ one problem solved the next one is waiting.

When I try to display the Max of a column and pass it to a text node it shows always

```auto
[{"":5}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/e/deb6f19a538818c4e4b4ca8a0ce94206e2e6b5a7.png)

**Query:**

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/1/81f9b22139c64686cf3c953ff9526108a182af62.png)

**Debug after mssql node:**

```auto
{"_msgid":"9512321323912e81","maxID":0,"payload":[{"":5}],"query":"SELECT MAX(meassurementID) FROM t_test\n\n\n\n\n\n\n\n","queryMode":"query","queryParams":[],"sqlInfo":[]}

```

**Settings for the text node:**

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

Is it necessary to use "somehow" a function node to convert the msg.payload?

---

<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:** [2 December 2022 19:20 UTC](https://discourse.nodered.org/t/dynamic-ms-sql-query-chart/71525/6 "2022-12-02T19:20:36Z")

</div>

You query needs to be something like 'SELECT MAX(measurementID) AS xxxTempxxx FROM t\_test;'

> [@ardukus](#):
>
> Is it necessary to use "somehow" a function node to convert the msg.payload?

You can use the change node, dependent on all the changes you want to do, it will handle most of them.

---

<div class="post-metadata">

**Author:** ![ardukus](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@ardukus](https://discourse.nodered.org/u/ardukus)\
**Post date:** [4 December 2022 16:36 UTC](https://discourse.nodered.org/t/dynamic-ms-sql-query-chart/71525/7 "2022-12-04T16:36:33Z")

</div>

when I try so with

```auto
SELECT MAX(meassurementID) AS maxID FROM t_imu

```

I get get my value like expected in a number.

```auto
{"_msgid":"b19c61b64b2c6bdd","payload":[{"maxID":3}],"query":"SELECT MAX(meassurementID) AS maxID FROM t_imu\n\n\n\n\n\n\n\n","queryMode":"query","queryParams":[{"output":true,"name":"param1","type":{},"options":{"nullable":true,"primary":false,"identity":false,"readOnly":false},"value":null},{"output":false,"name":"param2","type":{},"value":0,"options":{"nullable":true,"primary":false,"identity":false,"readOnly":false}}],"sqlInfo":[]}

```

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/d/9d803f1a5b83143a70aca02397f84a0d2285090e.png)

But when I try to parse it to the txt node it say NaN.

```auto
[
    {
        "id": "0cf99bf3c4da315d",
        "type": "template",
        "z": "dd2a1e9ef74cc87e",
        "name": "",
        "field": "payload",
        "fieldType": "msg",
        "format": "handlebars",
        "syntax": "mustache",
        "template": "SELECT MAX(meassurementID) AS maxID FROM t_imu\n\n\n\n\n\n\n\n",
        "output": "str",
        "x": 300,
        "y": 380,
        "wires": [
            [
                "5679ea5108442032"
            ]
        ]
    },
    {
        "id": "5679ea5108442032",
        "type": "MSSQL",
        "z": "dd2a1e9ef74cc87e",
        "mssqlCN": "5558b0cd5f739949",
        "name": "",
        "outField": "payload",
        "returnType": "0",
        "throwErrors": 1,
        "query": "SELECT timestamp, IMUValue \r\nFROM t_test\r\nWHERE meassurementID = @ID\r\nORDER BY timestamp \r\n ",
        "modeOpt": "queryMode",
        "modeOptType": "query",
        "queryOpt": "payload",
        "queryOptType": "msg",
        "paramsOpt": "",
        "paramsOptType": "editor",
        "rows": "rows",
        "rowsType": "msg",
        "params": [
            {
                "output": true,
                "name": "param1",
                "type": "VarChar",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            },
            {
                "output": false,
                "name": "param2",
                "type": "int",
                "valueType": "num",
                "value": "0",
                "options": {
                    "nullable": true,
                    "primary": false,
                    "identity": false,
                    "readOnly": false
                }
            }
        ],
        "x": 500,
        "y": 380,
        "wires": [
            [
                "d8cc003bf3f31218",
                "fd1a20bb186020c2"
            ]
        ]
    },
    {
        "id": "0d8ed7df651928d5",
        "type": "inject",
        "z": "dd2a1e9ef74cc87e",
        "name": "",
        "props": [],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 130,
        "y": 380,
        "wires": [
            [
                "0cf99bf3c4da315d"
            ]
        ]
    },
    {
        "id": "d8cc003bf3f31218",
        "type": "debug",
        "z": "dd2a1e9ef74cc87e",
        "name": "debug 16",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 620,
        "y": 280,
        "wires": []
    },
    {
        "id": "fd1a20bb186020c2",
        "type": "function",
        "z": "dd2a1e9ef74cc87e",
        "name": "function 20",
        "func": "var highestID = parseInt(msg.payload);\nmsg.payload = highestID;\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 730,
        "y": 380,
        "wires": [
            [
                "9c744a82c33a946a"
            ]
        ]
    },
    {
        "id": "9c744a82c33a946a",
        "type": "debug",
        "z": "dd2a1e9ef74cc87e",
        "name": "debug 28",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 920,
        "y": 300,
        "wires": []
    },
    {
        "id": "5558b0cd5f739949",
        "type": "MSSQL-CN",
        "tdsVersion": "7_4",
        "name": "",
        "server": "localhost",
        "port": "1433",
        "encyption": true,
        "trustServerCertificate": true,
        "database": "Node_Red_TestDB",
        "useUTC": true,
        "connectTimeout": "15000",
        "requestTimeout": "15000",
        "cancelTimeout": "5000",
        "pool": "5",
        "parseJSON": false,
        "enableArithAbort": true
    }
]

![image|334x281](upload://d0lJ5Ee9gTS0QSim0qpELBHOY6z.png)

```

---

<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:** [4 December 2022 19:18 UTC](https://discourse.nodered.org/t/dynamic-ms-sql-query-chart/71525/8 "2022-12-04T19:18:39Z")

</div>

You can use a change node to manipulate your JSON.

```auto
[{"id":"30b23a960afab3d2","type":"tab","label":"Flow 4","disabled":false,"info":"","env":[]},{"id":"d8cc003bf3f31218","type":"debug","z":"30b23a960afab3d2","name":"debug 16","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":280,"y":160,"wires":[]},{"id":"fd1a20bb186020c2","type":"function","z":"30b23a960afab3d2","name":"function 20","func":"var highestID = parseInt(msg.payload.payload[0].maxID);\nmsg.payload = highestID;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":290,"y":200,"wires":[["9c744a82c33a946a"]]},{"id":"9c744a82c33a946a","type":"debug","z":"30b23a960afab3d2","name":"debug 28","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":480,"y":220,"wires":[]},{"id":"cfb5cb574bf52b07","type":"inject","z":"30b23a960afab3d2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"_msgid\":\"b19c61b64b2c6bdd\",\"payload\":[{\"maxID\":3}],\"query\":\"SELECT MAX(meassurementID) AS maxID FROM t_imu\\n\\n\\n\\n\\n\\n\\n\\n\",\"queryMode\":\"query\",\"queryParams\":[{\"output\":true,\"name\":\"param1\",\"type\":{},\"options\":{\"nullable\":true,\"primary\":false,\"identity\":false,\"readOnly\":false},\"value\":null},{\"output\":false,\"name\":\"param2\",\"type\":{},\"value\":0,\"options\":{\"nullable\":true,\"primary\":false,\"identity\":false,\"readOnly\":false}}],\"sqlInfo\":[]}","payloadType":"json","x":130,"y":220,"wires":[["fd1a20bb186020c2","d8cc003bf3f31218","4f305fec71c25d95"]]},{"id":"4f305fec71c25d95","type":"change","z":"30b23a960afab3d2","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.payload[0].maxID","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":240,"wires":[["9c744a82c33a946a"]]}]

```

---

<div class="post-metadata">

**Author:** ![ardukus](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@ardukus](https://discourse.nodered.org/u/ardukus)\
**Post date:** [5 December 2022 19:47 UTC](https://discourse.nodered.org/t/dynamic-ms-sql-query-chart/71525/9 "2022-12-05T19:47:13Z")

</div>

aaah. THX! I tried it a 100 times in a similar way, but missed to declare "[0]".  
I use your solution now and it works flawless.

---

<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:** [19 December 2022 19:47 UTC](https://discourse.nodered.org/t/dynamic-ms-sql-query-chart/71525/10 "2022-12-19T19:47:54Z")

</div>

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