Good evening everyone, I’m starting to use Xojo again after many months of downtime. I have a problem with the syntax… I pass two string values: DataDaEliminareDallatabella which tells me the year of the records that I should delete from the table, and TavoloDaCuiEliminareRecords which tells me the name of the table, but something is wrong.
The table field Data_Spedizione is of the type dd/mm/YYYY
Var deleteSQL As String
deleteSQL = "DELETE FROM " + TabellaDaCuiEliminareRecords + " WHERE Year(Data_Spedizione)=#"+ DataDaEliminareDallatabella +"#"
Try
db.ExecuteSQL(deleteSQL)
Catch error As DatabaseException
MessageBox(db.ErrorMessage)
End Try
After I was asked about this, a short addition.
I would not use this syntax in this way. A database will perform better with a query that uses a comparison than extracting the year for each entry.
So:
SELECT * FROM `table` WHERE `datefield` BETWEEN '2023-01-01' AND '2023-12-31';
Good morning group, and first of all thank you all for the support, as always encouraging for me. I have been using a Microsoft Access database for many years now and it is full of data, so I am afraid to change it. I must say however that Xojo supports it well so far, and therefore I am able to use it well. The field is of type DATE in my table, I have to delete records that have a certain year in common based on the year that is indicated to me. So I have to delete the year 2002 from the database if I am asked for that year, so for example the date 02/01/2002, the date 05/07/2002 but not the date 04/05/2003 Sorry, I am not a professional programmer, so for me certain things are not obvious. Up to now I have solved all the problems with the dates … but now I can’t understand how to tell the program to delete all the data that have the year of the Data_Spedizione field equal to the one I need.
A lot depends upon how the Access DateTime fieds are represented in the ODBC driver you use.
They are accessed using syntax like #yyyy-MM-dd# in Access itself.
They may be exposed as strings in the driver
So you may have some luck trying:
dim txtStart as string = "#" + format(DataDaEliminareDallatabella, "0") + "-01-01#
dim txtEnd as string = "#" + format(DataDaEliminareDallatabella+1, "0") + "-01-01#
db.ExecuteSQL( "DELETE FROM " + TabellaDaCuiEliminareRecords + " WHERE Data_Spedizione >= " + txtStart + " and Data_Spedizione < " + txtEnd
or by generating these start/end dates as Xojo dates, and then using them in a parameterised query (always best…) in the expectation that the parameter will do whatever conversion is required