6

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?

abatishchev
  • 95,331
  • 80
  • 293
  • 426
medusa
  • 519
  • 3
  • 6
  • 21

3 Answers3

24

Use square brackets [] around the servername:

select  * 
from    [server-name].[db-name].[schema-name].[table-name]
Andomar
  • 225,110
  • 44
  • 364
  • 390
0

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

user4463876
  • 178
  • 1
  • 9
0

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]")
Senthuran
  • 1,211
  • 1
  • 12
  • 18