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
  • 49,743
  • 32
  • 103
  • 159
dksaldas
  • 51
  • 1
  • 2

3 Answers3

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

Try throwing square brackets around it:

select * from States where [State Name] = 'Michigan';
Abe Miessler
  • 82,532
  • 99
  • 305
  • 486
2

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

SELECT * 
  FROM States 
 WHERE "State Name" = 'Michigan';
onedaywhen
  • 55,269
  • 12
  • 100
  • 138