Why do I get the **ER_BAD_FIELD_ERROR: Unknown column VARIABLE in 'field list'** in this example?

Can someone tell me, what is wrong with this code?

I keep getting the "ER_BAD_FIELD_ERROR: Unknown column 'aarstal' in 'field list'" even though I am pretty sure I did the syntax correctly. I suspect the error to be in lines 11 to 14 but can't seem to see it. Any feedback is gladely appreciated.

Ps. I am sorry if this is in the wrong topic, if so, please move it to a more suitable topic. Thanks in advance

This forum is for Microsoft SQL Server - the syntax you are showing appears to be from MySQL which is a different product.

Based on the error - my guess is that the table already exists but was not created with all of the columns. So the INSERT statement is failing because that column does not exist in the actual table.

If you are trying to alter the table and add an additional column - the syntax for that would be ALTER TABLE and not CREATE TABLE.

1 Like

That is the same guess I had. In SQL Server, the query processor/optimizer would check the second query against current structures if it already existed and give you an error. SQL is typically an interpreted language, but it still so some syntax and object checking before execution. This could happen even if you included a DROP TABLE in the batch

1 Like

Dear Jeff

I beg your pardon, I missed the part on the forum which said it was only for Microsoft SQL, that i my bad. Your solution seems to work wonders. Cheers and have a wonderful day to you and @drsql!

1 Like