Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 720
Geetanjali Jain Avatar asked Sep 03 '25 16:09

Geetanjali Jain


1 Answers

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'
)
like image 58
Sean Lange Avatar answered Sep 05 '25 05:09

Sean Lange