SQLite SELECT with a WHERE condition

This is such a simple issue that I feel quite embarrassed to put it into print. I have an SQLite database where I want to retrieve data with a conditional WHERE. The WHERE condition refers to a numeric field. If I insert the actual value it works fine, but the moment I use a numeric variable it gives me a syntax error. This works -
rs = App.DB.SQLSelect(“SELECT MAX(Glucometer) AS MaxGluc FROM Carbcalc WHERE Minutes > (1061254490 - 43776)”)

This does not - rs = App.DB.SQLSelect(“SELECT MIN(Glucometer) AS MinGluc FROM Carbcalc WHERE Minutes > '” + TotMins_Month + “’”)

I’d really appreciate being put right on this one. many thanks, guys.

You are almost there:

rs = App.DB.SQLSelect("SELECT MIN(Glucometer) AS MinGluc FROM Carbcalc WHERE Minutes > '" + str(TotMins_Month) + "'")

the query is a string but if you search for a number in a number field you do not use ’
its more like this without quotes around the number

rs = App.DB.SQLSelect("SELECT MIN(Glucometer) AS MinGluc FROM Carbcalc WHERE Minutes > " + str(TotMins_Month) )

see also PreparedSQLStatement for older xojo version.

at newer xojo with api 2 the method SelectSQL have a parameter array. SelectSQL

Thanks Markus - works an absolute treat.You’re a star !!

@Mike Wyatt if this answers your question, please click the “This answers the question” button in the bottom right hand corner of Markus’ post.