我在以下SQL语句中组合两个WHERE语句时遇到问题:
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];
我想说Free在哪里等于Y而FirstLetter等于tmplike,但是上面没有用。
有人可以帮忙吗?
答案 0 :(得分:1)
您使用通配符,因此您希望LIKE
不等于(=);
... WHERE Free ='Y' AND FirstLetter LIKE '%@%'"
答案 1 :(得分:0)
尝试从最后删除%
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];
答案 2 :(得分:0)
尝试使用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];
答案 3 :(得分:0)
使用此工作正常
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];
答案 4 :(得分:0)
也许只是括号?
... WHERE (Free ='Y') AND (FirstLetter LIKE '%@')",tmpLike];