How to pass variables to the MSSQL-Node?

Hi,
I would like to insert several values into my MSSQL-Database using the MSSQL-Node.
Unfortunately it does not seem to work the way it is described.

I prepare an object with two variables:

var a = {};
a.SQL_Parameter = "Baroso";
a.SQL_Value = "1";
return a;

In the MSSQL-Node I try to use these two values in an INSERT-Statement:

insert into webtest
select getdate(),'test','{{{msg.SQL_Parameter}}}','{{{msg.SQL_Value}}}','','','','',''

All I get is one line with empty fields in the database-table.

[{"id":"66444e8c.457ed","type":"function","z":"607d461d.a97708","name":"True / False","func":"var a = {};\n\na.SQL_Parameter = \"Baroso\";\na.SQL_Value = \"1\";\n    \nreturn a;\n\n","outputs":1,"noerr":0,"x":450,"y":440,"wires":[["90f55686.238258","bfa799ab.b1cb48"]]},{"id":"90f55686.238258","type":"MSSQL","z":"607d461d.a97708","mssqlCN":"576100aa.9e891","name":"","query":"--INSERT INTO Weblog (id, name, quantity) VALUES ({{{payload.id}}}, \n--'{{{global.name}}}', 1)\n\ndeclare @hose varchar;\nset @hose = '{{{msg.SQL_Parameter}}}';\n\ninsert into webtest\nselect getdate(),'test',@hose,@hose,'','','','',''\n","outField":"payload","returnType":0,"throwErrors":1,"x":760,"y":420,"wires":[[]]},{"id":"bfa799ab.b1cb48","type":"debug","z":"607d461d.a97708","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":750,"y":360,"wires":[]},{"id":"d3992c9c.e9627","type":"inject","z":"607d461d.a97708","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":220,"y":440,"wires":[["66444e8c.457ed"]]},{"id":"576100aa.9e891","type":"MSSQL-CN","z":"","tdsVersion":"7_4","name":"","server":"10.0.0.19","port":"1433","encyption":true,"database":"WeblogDB","useUTC":true,"connectTimeout":"15000","requestTimeout":"15000","cancelTimeout":"5000","pool":"5"}]

Am I doing it wrong ?

BR
Gawan

any idea ?

@Golonder and anyone in the future.

you leave the msg part off

e.g. select getdate(),'test','{{{SQL_Parameter}}}','{{{SQL_Value}}}','','','','',''

I have just published an update to node-red-contrib-mssql-plus and clarifed this in the built in node help...

sorry for the delayed reply (I'm certain you got past this long ago)

Nice update to documentation however. I tripped over this issue in the past, had me guessing until some gave me insight.

1 Like