Skip to main content

Hi everyone!

Today I encountered the following problem:

We have an SQL-table with a column named "day-number". I'm trying to add a row to this table using dynamic SQL:

INSERT INTO DEV_YR_51.dbo.testtable (day-number, maximum) VALUES  (?,?)

After execution I get the following error:

Error: Insert to testtable unsuccessful (-) - Incorrect syntax near the keyword 'day'.

What causes this error? I tried using an underscore instead of a dash, but then the error is "Invalid column name 'day_number'"

Thanks for the help!

Regards,

Raffi


#underscoresql

Hi everyone!

Today I encountered the following problem:

We have an SQL-table with a column named "day-number". I'm trying to add a row to this table using dynamic SQL:

INSERT INTO DEV_YR_51.dbo.testtable (day-number, maximum) VALUES  (?,?)

After execution I get the following error:

Error: Insert to testtable unsuccessful (-) - Incorrect syntax near the keyword 'day'.

What causes this error? I tried using an underscore instead of a dash, but then the error is "Invalid column name 'day_number'"

Thanks for the help!

Regards,

Raffi


#underscoresql

A hyphen is not a legal character in a sql column so it needs to be masked.

Try enclsing the column name containing the hyphen in quotes or [].

Example:

INSERT INTO DEV_YR_51.dbo.testtable ("day-number", maximum) VALUES  (?,?)


Hi everyone!

Today I encountered the following problem:

We have an SQL-table with a column named "day-number". I'm trying to add a row to this table using dynamic SQL:

INSERT INTO DEV_YR_51.dbo.testtable (day-number, maximum) VALUES  (?,?)

After execution I get the following error:

Error: Insert to testtable unsuccessful (-) - Incorrect syntax near the keyword 'day'.

What causes this error? I tried using an underscore instead of a dash, but then the error is "Invalid column name 'day_number'"

Thanks for the help!

Regards,

Raffi


#underscoresql

Thanks, this was helpful.