Awan
Awan

Reputation: 18560

Select Query is not working with WHERE clasue when there is a space in Column Name

I have got SQL Server database in which Table column name have spaces. For example I have a Table something 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 a following query(column name with space) I get empty result:

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

And when I use following query(column name with no space) I get one accurate result:

SELECT * FROM table WHERE ID='1'

I am using SQL Server 2005

Thanks

Upvotes: 3

Views: 1588

Answers (1)

codingbadger
codingbadger

Reputation: 43974

You need wrap the column name in square brackets

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

Upvotes: 7

Related Questions