MySQL node, how to capitalize (only) the first letter of value when inserting?

I am using node-red-node-mysql to insert a row into a table in a database.

The function looks like this and works perfectly:

msg.payload = [msg.customerNumber, msg.orderNumber, msg.orderDate, msg.firstName]

msg.topic = "INSERT INTO orderTable(customerNumber, orderNumber, orderDate, firstName) VALUES(?, ?, ?, ?);"

return msg;

What I want to do is to format firstName before inserting it into the table.

If msg.firstName's value is martin I want to insert Martin.

If the value is mARTIn I also want to insert Martin.

How can I use UCASE/LCASE functions inside this function?

Well I find this works

msg.topic = "INSERT INTO test (description) VALUES(CONCAT(UCASE(LEFT('" + msg.payload + "', 1)), LCASE(SUBSTRING('" + msg.payload + "', 2))))"
return msg;

Edit: This works too

msg.topic = "INSERT INTO test (description) VALUES( CONCAT(UCASE(LEFT( ? , 1)), LCASE(SUBSTRING( ? , 2)))        )"
msg.payload = [msg.payload, msg.payload]
return msg;

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