Incorrect syntax near '-'

i am trying to run a query in another server and need to specify it in the select statement but the server name has got an '-' in it, like server-name. this is producing the error in the title. How can i fix it?

3 Answers

Use square brackets [] around the servername:

select * from [server-name].[db-name].[schema-name].[table-name] 

I came across an SQL query on some website, which was supposed to be correct, but I was getting the same error. It appears, that some websites format text and swap the minus sign with some Office-like abomination.

Incorrect minus character: –
Correct one: -

I also came across this error when I work with spring boot and MSSQL db. We may get this error, when we did not define the schema and the table name correctly. I have included the below schema name with square brackets in the model class and I could overcome this issue.

@Table(name = "FIELDS_PARAM",schema = "[sample-schema]") 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like