Reputation: 29064
I am writing an Iphone app and using sqlite as my database. I have a discount for objects if they are between a certain range (MIN and MAX), but the problem is when i do my query, the discounts seems to apply beyond that range as well. Not sure how to do it properly.
For example, I want the range between 36(MIN) to 60(MAX).
The sql statement looks like this:
NSString *queryString = [NSString stringWithFormat:@"SELECT * FROM DISCOUNT WHERE PACKAGEID = '%@' AND CATEGORYID = '%@' AND '%@' >= MIN ORDER BY MAX DESC ",item.packageid,item.categoryid,item.discount];
This code is my senior's. Need to change it.. Need some help on it... What am i doing wrong?
Upvotes: 0
Views: 92
Reputation: 31637
add AND '%@' <= MAX
in the query at the end after AND '%@' >= MIN
Your query should look like
NSString *queryString = [NSString stringWithFormat:@"
SELECT * FROM DISCOUNT WHERE PACKAGEID = '%@' AND CATEGORYID = '%@'
AND '%@' >= MIN AND '%@' <= MAX ORDER BY MAX DESC",
item.packageid,item.categoryid,item.discount,item.discount];
Upvotes: 2