Hi all,
Below is a snippet of my code, when a table name contains a hyphen, I get the error below. How can I fix this? Thanks for the help.
ex = {"ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near '-'."}
Hi all,
Below is a snippet of my code, when a table name contains a hyphen, I get the error below. How can I fix this? Thanks for the help.
ex = {"ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near '-'."}
Use []
round the column name:
CREATE TABLE [test2]
(cn VarChar(1024) NULL,
[tutor-id] VarChar(1024) NULL)
Or preferably stick to column names which don't require special treatment...
Note that it's a column name which has a hyphen, not the table name.
SQL doesn't like hyphens. Try enclosing tutor-id in square brackets: [tutor-id]
If you must, you might be able to work around this by setting the field name to [tutor-id]
rather than tutor-id
, but just renaming the field to tutorId
is an approach i'd rather take.
You can replace the hyphen by an underscore or enclose the name in [ and ].
Try:
CREATE Table [test2] ( [cn] varchar(1024) NULL, [tutor-id] varchar(1024) NULL )