tags:

views:

16

answers:

2

hi all, 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

A: 

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.

Felix
i know this thing . whether there are any method to perform this operation from query?
Rupesh
+1  A: 
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!

Ruchir Shah