GuybrushThreepwood
GuybrushThreepwood

Reputation: 5616

WHERE AND in Sqlite Statement

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

Answers (5)

yosh
yosh

Reputation: 3305

Maybe simply brackets ?

... WHERE (Free ='Y') AND (FirstLetter LIKE '%@')",tmpLike];

Upvotes: 0

Rahul Juyal
Rahul Juyal

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

Alex K.
Alex K.

Reputation: 175816

Your using a wildcard so you want LIKE not equality (=);

... WHERE Free ='Y' AND FirstLetter LIKE '%@%'"

Upvotes: 1

EXC_BAD_ACCESS
EXC_BAD_ACCESS

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

Narayana Rao Routhu
Narayana Rao Routhu

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

Related Questions