Thursday, 22 August 2013

Overcoming the reserved word "IN" in sql server

Overcoming the reserved word "IN" in sql server

Just for reference I am using SQL Azure.
I noticed when I am trying to select data from a table based on a license
plate and the state of that plate I get no results back if the state is
"IN". I realize the word "IN" is reserved in SQL server; however, I am
containing that within quotes in my query. I currently am in testing phase
and have only one record in the table which has a lisence plate 287YGB and
state IN.
If I write my query as follows I get nothing back.
SELECT MakeModel, CitizenID, VehicleID FROM tblVehicles WHERE
tblVehicles.Lisence = '287YGB' AND tblVehicles.PlateState = 'IN'
If I write my query this way I get back my result. But this is not good
enough.
SELECT MakeModel, CitizenID, VehicleID FROM tblVehicles WHERE
tblVehicles.Lisence = '287YGB'
And finally, if I write my query this way I get the only row in the table.
SELECT MakeModel, CitizenID, VehicleID FROM tblVehicles
From these tests I can see that the last where parameter is causing the
problem. I am assuming it is due to the fact that the word "IN" is
reserved. Is there a way around this?

No comments:

Post a Comment