views:

27

answers:

1

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

+6  A: 

You need wrap the column name in square brackets

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

Barry
Thanks. Its working.
Awan
Of course it is best to not use spaces or SQl keywords in your column names or other object names. If you haven't put this on prod yet, I'd change the field names so you don't have to use brackets.
HLGEM