MySQL to SQL Server

Hi !

Sorry for the dumb question, but I’m trying to synch values from a MySQL to a SQL Server. I’m connected to both db and I do run a Query on the MySQL to return the results I want

SELECT *
FROM prestashop_orders
WHERE extracted = 2;

Now I’d like insert some fields from the table to the SQL server, for exemple the value from the field “reference” from the MySQL table “prestashop_orders” to “Your Reference” field from the table Test$TempSalesHeader in the SQL Server.

Thanks for your help !

Hey @Jonathan,

Welcome to the community :cake:

Have you tried adding an Edit Fields node between the MySQL node and the SQL node to change the field names then using the insert option in the SQL node?

Hi ! Thanks for the prompt reply and idea !

Just tried, so far it looks like this but not sure I’m doing what I should, still get an error :frowning:

Hey @Jonathan,

What error are you seeing?

Unfortunately, error message is not very detailed !

Edit: on the screenshot it shows [‘Your Reference’],[‘Your Reference’] in columns, it was a test, I get the same error with only one [‘Your Reference’]

Well that is super helpful, I will have to fix that error :slight_smile:

What is the name of the column in the database is it just Your Reference?

:joy:

This is the column in the MySQL db

This is the column in the MSSQL db

image

I wonder if the space is causing the issue, Rather than [‘Your Reference’] what happens if you just try Your Reference or 'Your Reference'?

Hi!

When I try just ‘Your Reference’ I get
ERROR: Invalid column name ‘‘Your Reference’’.

It’s a bit better when I put Your Reference
ERROR: Cannot insert the value NULL into column ‘Interface Type’, table ‘NavOpal.dbo.Opal$TempSalesHeader’; column does not allow nulls. INSERT fails.

For information

I don’t know why it’s trying to insert into column Interface Type, it’s the first with a space in its name, if it’s of any help!

Hey @Jonathan,

What happens if you add the Interface Type to your query? It sounds like the Table requires an option for that which isn’t in the data you are sending.

Maybe I should try another way to do it

If I try this query

UPDATE Opal$TempSalesHeader
SET [Your Reference] = ‘123456’
WHERE [Source Document No_] = ‘989962’;

It does work.

Now, how can I synch for exemple “reference” to “Your Reference” ? How do I map them ?

That would do it, So in that case in your query you would need to change the numbers to use an expression based on the previous data.

UPDATE Opal$TempSalesHeader
SET [Your Reference] = {{ $json.reference }}
WHERE [Source Document No_] = ‘989962’;

With your code I get ERROR: Incorrect syntax near ‘‘’.

If I replace by ' I get ERROR: Invalid column name ‘undefined’. :face_with_monocle:

Did you change the field to use an expression?

Not sure what it means ?

But I did delete the edit part I previously used, and now

UPDATE Opal$TempSalesHeader
SET [Your Reference] = {{ $json.reference }}
WHERE [Source Document No_] = '989962';

It returns this error ERROR: Invalid column name 'GHWPIXTSO'. GHWPIXTSO being the value.

Also, I’m using self-hosted version, maybe that the issue ?

  • Self-hosted users can switch back to RiotTmpl: set N8N_EXPRESSION_EVALUATOR to tmpl. Refer to Environment variables for more information on configuring self-hosted n8n.

image

By looking at the result, $json.reference does get the value so this should work ! Why does it returns an error with column GHWPIXTSO ?!

Hey @Jonathan,

It may need '{{ $json.reference }}' so that the value is quoted.

Thank you so much for all the help !

Now I can begin (or at least try!) to make more complex workflows

Thanks once more !

1 Like

Hi !

One more question, is it possible to join two or more items into one column ? For example, I’d like to join '{{ $json.firstname}}' and '{{ $json.lastname }}' together so I get “Firstname Lastname” in my Customer column

Thanks!

I mean without using a merge :slight_smile:

Hey @Jonathan,

Should be pretty much what you have put so '{{ $json.firstname}} {{ $json.lastname }}' or maybe ‘{{ $json.firstname + " " + $json.lastname }}’