tags:

views:

174

answers:

6

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.

alt text

ex = {"ERROR [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near '-'."}

+4  A: 

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.

Jon Skeet
Arguably, OP just said the table contains the hyphen, not the table *name* =)
David Hedlund
@David: "when a table name contains a hyphen" seems pretty clear to me ;)
Jon Skeet
Thanks, I can't avoid the hyphen it's included in the data I receive, thanks all I'll try [table-id].
Jamie
+2  A: 

SQL doesn't like hyphens. Try enclosing tutor-id in square brackets: [tutor-id]

peacedog
+3  A: 

Use [tutor-id]

gbn
+3  A: 

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.

David Hedlund
+2  A: 

You can replace the hyphen by an underscore or enclose the name in [ and ].

Eric Minkes
+1  A: 

Try:

CREATE Table [test2] ( [cn] varchar(1024) NULL, [tutor-id] varchar(1024) NULL )

Michael Alves