2011-09-30 59 views
1

我有合併兩個一個問題,在下面的SQL語句語句:WHERE和SQLite中陳述

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

我想說這裏免費等於Y和FirstLetter等於tmplike,但是上述不管用。

任何人都可以幫忙嗎?

回答

0

試試這個REMOVE%從去年

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]; 
+0

仍然是同樣的問題。 – GuybrushThreepwood

+1

不工作意味着你正在收到錯誤 – Narayana

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]; 
+0

仍然是同樣的問題。 – GuybrushThreepwood

+0

wat error ur getting exactly –

+1

首先你嘗試使用Sqlite Browser或其他工具,並使用tat查詢 –

1

你使用通配符讓你想不LIKE平等(=);

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

以獲得更好的性能:... WHERE Free ='Y'AND FirstLetter LIKE '@%'」。 –

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]; 
0

也許只是括號?

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