[SOLVED] Filter in sql expression for DB Access

Good evening group. I would like to create a filter in the SQL expression … it should be something like this:

Dim AnnoDaGestire as string
AnnoDaGestire="2022"
rows = db.SelectSQL("SELECT * FROM Ingressi where Year(Data)=#"+ AnnoDaGestire+"#")

data is the database field that contains the date of the type dd / mm / yyyy.
I would like to be able to select in the sql expression, all the fields in which the year is the same as the one I am looking for.

You’re close … it should work if you remove # around the year. I’m not sure why you have them. Microsoft Access uses # around date values, but you’re specifying only the year which is a number.

Also this assumes your database supports the Year function. (MS Access and MySQL do.)

Better way (avoids SQL injection security issues):

rows = db.SelectSQL("SELECT * FROM Ingressi where Year(Data)=?", AnnoDaGestire)

If this doesn’t help, please let us know any errors you get, or describe the unexpected results.

Perfect … sorry I did not notice that.
Thanks.