Hi here is an example, when button is pressed a context storage variable is set to yes, when sql query is created it checks for context variable and if not null will add binChanged to the sql query, Then it resets the context variable to null.
[{"id":"491bc432.e6df9c","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"sensor/temperature","payload":"20","payloadType":"num","x":170,"y":2900,"wires":[["453a8e19.b837f"]]},{"id":"453a8e19.b837f","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"$split(topic,\"/\")[-1]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":2920,"wires":[["ef28ab87.99c3f"]]},{"id":"2942f0bd.4b7c9","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"sensor/pressure","payload":"900","payloadType":"num","x":170,"y":2940,"wires":[["453a8e19.b837f"]]},{"id":"da1f5838.4c3888","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"sensor/humidity","payload":"70","payloadType":"num","x":180,"y":2980,"wires":[["453a8e19.b837f"]]},{"id":"9e8536cc.fd8638","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"sensor/gas","payload":"27","payloadType":"num","x":160,"y":3020,"wires":[["453a8e19.b837f"]]},{"id":"ef28ab87.99c3f","type":"join","z":"c74669a0.6a34f8","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"4","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":430,"y":3000,"wires":[["6b4e4ffb.c83298"]]},{"id":"6b4e4ffb.c83298","type":"function","z":"c74669a0.6a34f8","name":"","func":"let binChange = flow.get(\"binChange\") || null,\nvalues=[new Date().valueOf(), \n msg.payload.temperature,\n msg.payload.pressure,\n msg.payload.humidity,\n msg.payload.gas,\n `'${binChange}'`]\ncolumns=[\"Date\", \"temperature\", \"pressure\", \"humidity\", \"gas\", \"binChange\"];\nif(binChange=== null){\n columns.pop();\n values.pop();\n}else{\n flow.set(\"binChange\", null);\n}\n\nmsg.topic =`INSERT INTO table_name (${columns.join(\", \")}) VALUES (${values.join(\", \")});`;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":590,"y":3000,"wires":[["327aee38.7d8842"]]},{"id":"327aee38.7d8842","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":690,"y":2920,"wires":[]},{"id":"dd75a682.36c55","type":"inject","z":"c74669a0.6a34f8","name":"button","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":100,"y":3140,"wires":[["a3859e2b.69456"]]},{"id":"a3859e2b.69456","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"binChange","pt":"flow","to":"yes","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":3140,"wires":[[]]}]
[edit]
And here it is altered so it will enter changed and not changed.
[{"id":"491bc432.e6df9c","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"sensor/temperature","payload":"20","payloadType":"num","x":170,"y":2900,"wires":[["453a8e19.b837f"]]},{"id":"453a8e19.b837f","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"$split(topic,\"/\")[-1]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":2920,"wires":[["ef28ab87.99c3f"]]},{"id":"2942f0bd.4b7c9","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"sensor/pressure","payload":"900","payloadType":"num","x":170,"y":2940,"wires":[["453a8e19.b837f"]]},{"id":"da1f5838.4c3888","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"sensor/humidity","payload":"70","payloadType":"num","x":180,"y":2980,"wires":[["453a8e19.b837f"]]},{"id":"9e8536cc.fd8638","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"sensor/gas","payload":"27","payloadType":"num","x":160,"y":3020,"wires":[["453a8e19.b837f"]]},{"id":"ef28ab87.99c3f","type":"join","z":"c74669a0.6a34f8","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"4","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":430,"y":3000,"wires":[["6b4e4ffb.c83298"]]},{"id":"6b4e4ffb.c83298","type":"function","z":"c74669a0.6a34f8","name":"","func":"let binChange = flow.get(\"binChange\") || \"not changed\",\nvalues=[new Date().valueOf(), \n msg.payload.temperature,\n msg.payload.pressure,\n msg.payload.humidity,\n msg.payload.gas,\n `'${binChange}'`]\ncolumns=[\"Date\", \"temperature\", \"pressure\", \"humidity\", \"gas\", \"binChange\"];\nif(binChange===\"changed\") flow.set(\"binChange\", \"not changed\");\nmsg.topic =`INSERT INTO table_name (${columns.join(\", \")}) VALUES (${values.join(\", \")});`;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":590,"y":3000,"wires":[["327aee38.7d8842"]]},{"id":"327aee38.7d8842","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":570,"y":2740,"wires":[]},{"id":"dd75a682.36c55","type":"inject","z":"c74669a0.6a34f8","name":"button","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"changed","payloadType":"str","x":100,"y":3140,"wires":[["a3859e2b.69456"]]},{"id":"a3859e2b.69456","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"binChange","pt":"flow","to":"changed","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":3140,"wires":[[]]}]