2

We need to retrieve data from a MS SQL server from a client with a diaeresis in the table name (which is bad practice). The table name is BE België$Cities and we are not allowed to change the table name. The request SELECT * FROM [BE België$Cities] returns a table not found error.

How can we retrieve data from this table? We are using SQL Server 2008, PHP7 and Laravel 5.3.

Gerard de Visser
  • 7,590
  • 9
  • 50
  • 58
  • 1
    have you tried with back tick in table name ?? visit this link : http://stackoverflow.com/a/10443100/4952944 – Bhavin Oct 14 '16 at 09:51
  • Dear Gerard, I have no issue retrieving data in ssms using : `SELECT * FROM dbo.België$Cities` on SQL SERVER 2012 via SSMS It might be related to a collation issue between sql server and PHP. – Kilren Oct 14 '16 at 11:08
  • The server is SQL SERVER 2008. – Gerard de Visser Oct 14 '16 at 11:28

1 Answers1

0

Had this problem a lot aswell so I made it a rule to myself to always use a back-tick (`) on tablenames, which should fix your problem.

In your case

SELECT * FROM `België$Cities`;

should work.

jogoe
  • 482
  • 6
  • 18
  • Back tick are not used in SQL SERVER where square brackets are used. see: http://stackoverflow.com/questions/10573922/what-does-the-sql-standard-say-about-usage-of-backtick – Kilren Oct 14 '16 at 11:12
  • Replacing square brackets with backticks does not work. I've also added to the question that the name also contains a space. Not sure if that matters. – Gerard de Visser Oct 14 '16 at 11:27