kunguito
05-05-2008, 02:43 AM
I don't know how to build an SQL query that:
Given a set of tables of the same structure and being a date one of their fields, retrieves the closest date to a parameter input date.
qry = " SELECT TOP 1 Date_stock " & _
"FROM " & _
"(SELECT Date_stock FROM table1 GROUP BY Date_stock; Union " & _
"SELECT Date_stock FROM table2 GROUP BY Date_stock; Union " & _
"SELECT Date_stock FROM table3 GROUP BY Date_stock;) " & _
"ORDER BY Abs(#" & Format(InputDate, ("mm/dd/yyyy")) & "#-CDate(Date_stock)) ASC;"
VBA says that there's a mistake in the FORM clause.
There must be a much simpler way to perform that. For example, instead of sorting the whole thing just retrieving a minimum.
Given a set of tables of the same structure and being a date one of their fields, retrieves the closest date to a parameter input date.
qry = " SELECT TOP 1 Date_stock " & _
"FROM " & _
"(SELECT Date_stock FROM table1 GROUP BY Date_stock; Union " & _
"SELECT Date_stock FROM table2 GROUP BY Date_stock; Union " & _
"SELECT Date_stock FROM table3 GROUP BY Date_stock;) " & _
"ORDER BY Abs(#" & Format(InputDate, ("mm/dd/yyyy")) & "#-CDate(Date_stock)) ASC;"
VBA says that there's a mistake in the FORM clause.
There must be a much simpler way to perform that. For example, instead of sorting the whole thing just retrieving a minimum.