Geetanjali Jain
Geetanjali Jain

Reputation: 402

Forward slash in column name throwing an incorrect syntax "/"

I am trying to execute insert query using Apache meta model on a sql server database - Where insert query contains a column name with forward slash(/) in it such as 'col4a/col4b' and query will be created by metamodel as

INSERT INTO dbo."table1" (col1,"col2 Type",col3,col4a/col4b) VALUES ('value1','value2','value3','value4')

When I execute this statement the code throws an error incorrect syntax near '/'.

Can anyone suggest me a solution to escape special character like / in my column name.

Upvotes: 4

Views: 6377

Answers (1)

Sean Lange
Sean Lange

Reputation: 33581

The proper way to handle poorly named columns in sql server is with square brackets [ ].

INSERT INTO dbo.table1 
(
    col1
    , [col2 Type]
    , col3
    , [col4a/col4b]
) 
VALUES 
(
    'value1'
    , 'value2'
    , 'value3'
    , 'value4'
)

Upvotes: 4

Related Questions