I am using a MS SQL Server node to Insert data into a database.
First of all, I am not really sure what the ‘Columns’ parameter means in the node settings:
I am able to use it successfully, however, I always make sure the SQL Server column names are exactly the same as the N8N JSON column names. First question, is this field meant for the N8N/MSSQL/or Both column names?
My second question revolves around using spaces in these column names. Since spaces are allowed in both the N8N json and the MSSQL column names I wanted to use them for longer column names. However, I keep gettiing “Incorrect syntax” errors:
I tried a combination of using quotes and brackets to solve this issue, and while I was able to get rid of the error this way, I did not get any populated columns with data, any help would be kindly appreciated.
Imagine that the node before the SQL Server node return:
{
firstname: 'ricardo',
lastname: 'espinoza",
}
If you wanted to insert just the firstname, the parameter columns have to be set to firstname.
To answer your question: The fields defined in the “columns” field are the fields you want to pick up from the input. In the SQL Server node context, it means the fields that you want to insert.
My second question revolves around using spaces in these column names. Since spaces are allowed in both the N8N json and the MSSQL column names I wanted to use them for longer column names. However, I keep gettiing “Incorrect syntax” errors:
Spaces should not be an issue. I have not tested it though. Can you provide an example of the string you are using in columns? Also, can you try removing the spaces after the commas if you have one?
Line 284:
The columnString is used as “INSERT INTO ${table}(${columnString})”, which does not allow for spaces since here it is used as the name of a MS SQL column. It should probably be made safe by adding double quotes or square brackets.
Does this also mean that the column list is used both in the SQL statement INSERT INTO and in the selection of fields from the json in N8N? So that the column names have to be exactly the same between SQL and N8N?