HurkNburkS HurkNburkS - 2 months ago 16
MySQL Question

Select Row if date Column is Between start and end date FMDB Request

I am trying to write a SQL query for FMDB i have in my Objective C project.

My table consists of an id, num_of_items, startDate, endDate.

My query looks like this

FMResultSet * result = [database executeQuery:@"SELECT * FROM mytablename WHERE date BETWEEN ? AND ? ", lstartDate, lendDate];


however when this code runs I am getting the following error after the app crashes

[1210:2007096] DB Error: 1 "near "TRUNCATE": syntax error"
[1210:2007096] DB Query: TRUNCATE mytablename


The date column contains long values, I have checked both lstartDate and lendDate both of which are in the database table in that column.

The result I am after is that all values between and including start and end date are included in the output.

any help would be greatly appreciated!

Answer

Try putting a single quote ' either side of the ?. Like this:

FMResultSet * result = [database executeQuery:@"SELECT * FROM mytablename WHERE date BETWEEN '?' AND '?' ", lstartDate, lendDate];