medusa
medusa

Reputation: 541

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?

Upvotes: 6

Views: 20413

Answers (3)

Senthuran
Senthuran

Reputation: 1857

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]")

Upvotes: 0

Human programmer
Human programmer

Reputation: 504

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: -

Upvotes: 0

Andomar
Andomar

Reputation: 238296

Use square brackets [] around the servername:

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

Upvotes: 25

Related Questions