Select Query does not work with WHERE clasue when there is a space in the Column Name field

I have a SQL Server database in which the table column name has spaces. For example, I have a table like this:

ID| First Name| Last Name|Birth Date 
1 | Wasim     | Akram    | 01-01-2000
2 | Saeed     | Anwer    | 01-01-2001

Now, when I use the following query (column name with a space), I get an empty result:

SELECT * FROM table WHERE 'First Name'='Wasim'

And when I use the following query (column name without space), I get one exact result:

SELECT * FROM table WHERE ID='1'

I am using SQL Server 2005

thank

+3
source share
1 answer

You need to wrap the column name in square brackets

SELECT * FROM table WHERE [First Name]='Wasim'

+7
source

Source: https://habr.com/ru/post/1770073/


All Articles