Quote:
Originally Posted by anniebai
In our database, the publication year and month are saved in different columns, the query is to find out the pubs after 7/1/2006. ... SELECT Publications.PubYear, Publications.PubMonth, format(mid(PubMonth,1,3) & ' 1,' & PubYear, 'short date') AS Expr2,mid(PubMonth,1,3), IsDate(DateValue(format(mid(PubMonth,1,3) & ' 1,' & PubYear, 'short date')))
FROM [select * from publications where PubYear is not null and pubMonth is not null and (pubyear=2006 or pubyear=2007)]. as Publications
where format(mid(PubMonth,1,3) & ' 1,' & PubYear, 'short date') >= #2006-07-01#
Hi Anniebai. The use of Format is not helping you here. Format returns a string representation of a date, not a date as it is internally stored (as a number). You are also using a subquery, which seems a lot for a simple query.
As you already hold the year and month values as discrete columns within your publication table (assuming these are integers), you could compare these directly with the year and month you need to find:
-
-
Select * from publications where (PubYear >= 2006) AND (PubMonth>=7);
-
If the PubYear and PubMonth values are text rather than Integers or Longs you can convert them to integers using the CInt function (e.g.
where (CInt(PubYear) > 2006)...
If you do need to convert your publication year and month to dates, use DateSerial instead of Format:
-
-
Select * from publications where (DateSerial(PubYear, PubMonth, 1) >= #07/01/2006#;
-
Note that the standard Access format of a date value given inside the hashes is mm/dd/yyyy, not yyyy-mm-dd as in your SQL.
Hope this helps.
-Stewart