microsoft/mssql-jdbc

[QUESTION] What is the right way to query a column with spaces in it? [getting Invalid column name]

nandinir-db opened this issue · 3 comments

Question

What is the right way to query a column with spaces in it?
SELECT * FROM xx.xx.xx
WHERE "Name Space" = 'John' --1 // returns no result although we have a row with data John
WHERE Name Space = 'John' --2 // says Invalid column name 'Name Space'.
WHERE [Name Space] = 'John' --3 // Invalid syntax - [PARSE_SYNTAX_ERROR] Syntax error
Stacktrace says it is from the com.microsoft.sqlserver.jdbc.SQLServerConnection

SELECT Name Space FROM xx.xx.xx works.

Relevant Issues and Pull Requests

I don't think there is anything wrong with the driver. This definitely looks like you have a incorrectly formatted SQL query. I have been able to successfully create 2 different queries, one in SQL Server Management Studio and the other in a test app:

select * from DemoDatabase.dbo.tblCountries where [Country Name]='Norway';
select * from DemoDatabase.dbo.tblCountries where "Country Name"='Norway';

Both queries successfully return the expected data.

Please let us know if this answers your question.

Hi @nandinir-db,

Does the response above answer your question? Without further communication we'll assume the issue is resolved, and move forward with closing the issue.

Hi @nandinir-db,

As we have not heard back from you, we will be closing this issue. Please feel free to reopen the issue if you need further assistance.