in my table of sqlite database, there are fields named id,firstName,middle, lastName
now i want to run the query as following
MyQuery = [NSString stringWithFormat:@"select id,(firstName || middlename || lastname) as Name from Students where firstname like '%@' or开发者_高级运维 middlename like '%@' or lastname like '%@'",searchBarString,searchBarString,searchBarString];
above query work well. but i want to add a space between first and middle name(also middle and last name). so how can i perform this task? please suggest
MyQuery = [NSString stringWithFormat:@"select id,(firstName || ' ' || middlename || ' ' || lastname) as Name from Students where firstname like '%@' or middlename like '%@' or lastname like '%@'",searchBarString,searchBarString,searchBarString];
Try this!
You could simply return the three columns in separate variables and then join them when displaying them:
NSString *lastName = ...;
NSString *middleName = ...;
NSString *firstName = ...;
NSString *joined = [NSString stringWithFormat:@"%@ %@ %@",lastName,middleName,firstName];
This has the advantage that you can sort by any of the three columns in the UI without making new sqlite queries and allow the user to edit these.
精彩评论