在哪里和Sqlite声明

时间:2011-09-30 10:12:35

标签: iphone sql xcode sqlite

我在以下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,但是上面没有用。

有人可以帮忙吗?

5 个答案:

答案 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];