Incorrect syntax near '-'
i am trying 开发者_如何学JAVAto 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?
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]")
精彩评论