Cheetah
Cheetah

Reputation: 14419

Insert into statement with parentheses in column names

I am use Java to insert into a MSSQL database. I have column names with parentheses in them like Duration_(Mins).

I am trying to execute a statement like:

INSERT INTO mytable (Duration_(Mins)) VALUES (?)

and I am getting the following error:

Exception in thread "main" java.sql.SQLException: Incorrect syntax near '('

So I am guessing I need some way to "escape" the bracket?

Upvotes: 1

Views: 1873

Answers (1)

Mubin
Mubin

Reputation: 4239

For MS-SQL Server, this should work:

INSERT INTO mytable ([Duration_(Mins)]) VALUES (?)

For details, refer this link: http://msdn.microsoft.com/en-us/library/ms132046.aspx#DelimitedIdentifiers

Upvotes: 3

Related Questions