Copy datetime from a table to another table

Hi, no offence @cubical but I guess you are not very proficient with node-red?

You seem to be branching off then re-joining when infact you can simply do everything in series...

What you had...

What I propose

image



Also, you appear to be avoiding the SQL Params & using mustache instead! why? Params are safe from SQL Injection hacks and IMO easer to use/understand.


Test Flow

use CTRL-I to import (NOTE: Untested since I dont have your DB)

[{"id":"db30356beffb06d1","type":"inject","z":"8cd81203fdd0b810","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"No Operator","payload":"1","payloadType":"num","x":210,"y":140,"wires":[["275ac3bc4209aeed"]]},{"id":"275ac3bc4209aeed","type":"MSSQL","z":"8cd81203fdd0b810","mssqlCN":"75a62ffff4c55db2","name":"Start Time","outField":"payload","returnType":0,"throwErrors":1,"query":"select * from trans_time where id_machine = @machineID;","modeOpt":"queryMode","modeOptType":"query","queryOpt":"payload","queryOptType":"editor","paramsOpt":"","paramsOptType":"editor","rows":"rows","rowsType":"msg","params":[{"output":false,"name":"machineID","type":"int","valueType":"msg","value":"payload","options":{"nullable":true,"primary":false,"identity":false,"readOnly":false}}],"x":370,"y":140,"wires":[["1547581edda91397","a36af554d806823b"]]},{"id":"1547581edda91397","type":"MSSQL","z":"8cd81203fdd0b810","mssqlCN":"75a62ffff4c55db2","name":"Stop Category","outField":"payload","returnType":0,"throwErrors":1,"query":"update machine_master \r\nset start = @start, category = @category\r\nwhere id_machine = @machineID\r\n\r\n","modeOpt":"queryMode","modeOptType":"query","queryOpt":"payload","queryOptType":"editor","paramsOpt":"","paramsOptType":"editor","rows":"rows","rowsType":"msg","params":[{"output":false,"name":"machineID","type":"Int","valueType":"msg","value":"payload[0].id_machine","options":{"nullable":true,"primary":false,"identity":false,"readOnly":false}},{"output":false,"name":"start","type":"DateTime","valueType":"msg","value":"payload[0].start","options":{"nullable":true,"primary":false,"identity":false,"readOnly":false}},{"output":false,"name":"category","type":"VarChar","valueType":"msg","value":"topic","options":{"nullable":true,"primary":false,"identity":false,"readOnly":false}}],"x":540,"y":140,"wires":[["ad557ce11dbf4832"]]},{"id":"ad557ce11dbf4832","type":"debug","z":"8cd81203fdd0b810","name":"test#1 result","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":710,"y":140,"wires":[]},{"id":"4120a6262867b6d2","type":"inject","z":"8cd81203fdd0b810","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"No Operator","payload":"1","payloadType":"num","x":210,"y":300,"wires":[["330e9050c608466c"]]},{"id":"330e9050c608466c","type":"MSSQL","z":"8cd81203fdd0b810","mssqlCN":"75a62ffff4c55db2","name":"Stop Category","outField":"payload","returnType":0,"throwErrors":1,"query":"declare @t datetime\r\nselect @t = start from trans_time where id_machine = @machineID\r\n\r\nupdate machine_master\r\nset start = @start, category = @category\r\nwhere id_machine = @machineID\r\n\r\n","modeOpt":"queryMode","modeOptType":"query","queryOpt":"payload","queryOptType":"editor","paramsOpt":"","paramsOptType":"editor","rows":"rows","rowsType":"msg","params":[{"output":false,"name":"machineID","type":"Int","valueType":"msg","value":"payload","options":{"nullable":true,"primary":false,"identity":false,"readOnly":false}},{"output":false,"name":"category","type":"VarChar","valueType":"msg","value":"topic","options":{"nullable":true,"primary":false,"identity":false,"readOnly":false}}],"x":380,"y":300,"wires":[["3036d374372b0f82"]]},{"id":"3036d374372b0f82","type":"debug","z":"8cd81203fdd0b810","name":"test#2 result","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":550,"y":300,"wires":[]},{"id":"681ec23c81c08610","type":"comment","z":"8cd81203fdd0b810","name":"TEST # 1:  get from DB, do some property moving/reshuffling, do the update query","info":"","x":420,"y":100,"wires":[]},{"id":"e60f84c64d27e1e9","type":"comment","z":"8cd81203fdd0b810","name":"TEST # 2:  Do everything in one go","info":"","x":280,"y":260,"wires":[]},{"id":"a36af554d806823b","type":"debug","z":"8cd81203fdd0b810","name":"What do you see in here?","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":570,"y":200,"wires":[]},{"id":"75a62ffff4c55db2","type":"MSSQL-CN","tdsVersion":"7_4","name":"","server":"localhost","port":"1433","encyption":true,"trustServerCertificate":true,"database":"OEE","useUTC":true,"connectTimeout":"1000","requestTimeout":"10000","cancelTimeout":"1000","pool":"5","parseJSON":false,"enableArithAbort":true}]
1 Like