Thank you very much Steve, I prefer you show me, I am new and I get lost with so many concepts. This is my flow:
[{"id":"d381fc46.a9b57","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"bae1ef9f.e7aec","type":"s7 control","z":"d381fc46.a9b57","endpoint":"ab1b0b4c.23e","function":"trigger","name":"lectura PLC","x":310,"y":320,"wires":[["a6b880f3.4da9a","caef5eb7.67442"]]},{"id":"2b668d2f.1a8512","type":"inject","z":"d381fc46.a9b57","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":320,"wires":[["bae1ef9f.e7aec"]]},{"id":"a6b880f3.4da9a","type":"delay","z":"d381fc46.a9b57","name":"","pauseType":"delay","timeout":"3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":460,"y":320,"wires":[["146bfe2d.e9f892"]]},{"id":"caef5eb7.67442","type":"debug","z":"d381fc46.a9b57","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":470,"y":280,"wires":[]},{"id":"22729ddf.b16102","type":"s7 in","z":"d381fc46.a9b57","endpoint":"ab1b0b4c.23e","mode":"single","variable":"Bobina","diff":true,"name":"","x":110,"y":100,"wires":[["2a0fffc0.3f985"]]},{"id":"146bfe2d.e9f892","type":"MSSQL","z":"d381fc46.a9b57","mssqlCN":"c2b5f2da.cf8d","name":"MSSQL","outField":"payload","returnType":0,"throwErrors":1,"query":"\nDECLARE @Maquina VARCHAR\nDECLARE @Bobina BIT\n\nSET @Bobina = {{{flow.Bobina}}};\nSET @Maquina = '{{{msg.maqui}}}';/*here the problem*/\n\nIF not exists(SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' AND TABLE_NAME = 'tablaLogo')\n CREATE TABLE tablaLogo\n\n (\n id INT IDENTITY(1,1) NOT NULL PRIMARY KEY,\n FechaHora DATETIME,\n Maquina VARCHAR,\n Bobina INT\n )\n\nELSE INSERT INTO tablaLogo\n (\n FechaHora,\n Maquina,\n Bobina\n \n )\n VALUES\n (\n GETUTCDATE(), /*para la hora local poner CURRENT_TIMESTAMP */\n @Maquina,\n @Bobina\n \n )\n\n","modeOpt":"","modeOptType":"query","queryOpt":"","queryOptType":"editor","paramsOpt":"","paramsOptType":"none","rows":"rows","rowsType":"msg","params":[],"x":620,"y":320,"wires":[[]]},{"id":"2a0fffc0.3f985","type":"change","z":"d381fc46.a9b57","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"true","fromt":"bool","to":"1","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"false","fromt":"bool","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":100,"wires":[["694eac0f.308ba4"]]},{"id":"3809eee7.ef8312","type":"debug","z":"d381fc46.a9b57","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":590,"y":60,"wires":[]},{"id":"694eac0f.308ba4","type":"function","z":"d381fc46.a9b57","name":"","func":"var maqui = {payload:'novoflex'}; /*this variable*/\nflow.set(\"Bobina\", msg.payload); /*the variable of PLC is correct*/\n\nreturn [msg, maqui];\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":100,"wires":[["3809eee7.ef8312"],["50340b1e.fc96a4"]]},{"id":"50340b1e.fc96a4","type":"debug","z":"d381fc46.a9b57","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":120,"wires":[]},{"id":"ab1b0b4c.23e","type":"s7 endpoint","transport":"iso-on-tcp","address":"192.168.0.3","port":"102","rack":"0","slot":"2","localtsaphi":"01","localtsaplo":"00","remotetsaphi":"02","remotetsaplo":"00","connmode":"tsap","adapter":"","busaddr":"","cycletime":"0","timeout":"1500","name":"S7-LOGO8","vartable":[{"addr":"DB1,X1064.0","name":"Bobina"},{"addr":"DB1,INT1118","name":"Altura"}]},{"id":"c2b5f2da.cf8d","type":"MSSQL-CN","tdsVersion":"7_4","name":"MSSQL","server":"192.168.0.4","port":"1433","encyption":true,"trustServerCertificate":true,"database":"LOGO","useUTC":true,"connectTimeout":"15000","requestTimeout":"15000","cancelTimeout":"5000","pool":"5","parseJSON":false,"enableArithAbort":true}]
Admin edit - wrap code with three backticks