5

I'm trying to run a statement where I retrieve tuples from a database. However my attribute has a space which is "State Name".

Im calling the SQL statement as follows:

select * from States where State Name = 'Michigan';

I'm pretty sure there is something wrong with the attribute having a space. How can I fix this problem without changing the name of the attribute? How can I call a SQL statement with the attribute constraint having a space?

Thanks,

Joe Phillips
  • 47,092
  • 28
  • 100
  • 152
dksaldas
  • 51
  • 1
  • 2

3 Answers3

10
select * from States where [State Name] = 'Michigan';
Tushar
  • 1,220
  • 1
  • 8
  • 17
2

Try throwing square brackets around it:

select * from States where [State Name] = 'Michigan';
Abe Miessler
  • 79,479
  • 96
  • 291
  • 470
2

The Standard SQL delimiter (and supported by SQL Server) is the double quote e.g.

SELECT * 
  FROM States 
 WHERE "State Name" = 'Michigan';
onedaywhen
  • 53,058
  • 12
  • 94
  • 134