Reputation: 5616
I am having a problem combining two WHERE statements in the following SQL statement :
query = [[NSString alloc] initWithFormat: @"SELECT Name, Description,Postcode,AddressLine1, ImageURL, Free, Area, OpeningTimes, NearestTube, Cost,UniqueID, URL, Number, FirstLetter FROM MainDetails WHERE Free ='Y' AND FirstLetter = '%@%'",tmpLike];
I want to say where Free is equal to Y and FirstLetter is equal to tmplike, however the above is not working.
Can anyone help ?
Upvotes: 1
Views: 1279
Reputation: 3305
Maybe simply brackets ?
... WHERE (Free ='Y') AND (FirstLetter LIKE '%@')",tmpLike];
Upvotes: 0
Reputation: 2144
use this one it work fine
query = [[NSString alloc] initWithFormat: @"SELECT Name, Description,Postcode,AddressLine1, ImageURL, Free, Area, OpeningTimes, NearestTube, Cost,UniqueID, URL, Number, FirstLetter FROM MainDetails WHERE Free ='Y' AND FirstLetter LIKE '%@ %%'",tmpLike];
Upvotes: 0
Reputation: 175816
Your using a wildcard so you want LIKE
not equality (=);
... WHERE Free ='Y' AND FirstLetter LIKE '%@%'"
Upvotes: 1
Reputation: 2707
try with escape char '/'
query = [[NSString alloc] initWithFormat: @"SELECT Name, Description,Postcode,AddressLine1, ImageURL, Free, Area, OpeningTimes, NearestTube, Cost,UniqueID, URL, Number, FirstLetter FROM MainDetails WHERE Free ='Y' AND FirstLetter = '%@\%'",tmpLike];
Upvotes: 0
Reputation: 6323
TRY THIS REMOVE % FROM LAST
query = [[NSString alloc] initWithFormat: @"SELECT Name, Description,Postcode,AddressLine1, ImageURL, Free, Area, OpeningTimes, NearestTube, Cost,UniqueID, URL, Number, FirstLetter FROM MainDetails WHERE Free ='Y' AND FirstLetter = '%@'",tmpLike];
Upvotes: 0