GUIDO22 Registered User. Local time Today, 20:59 Joined Nov 2, 2003 Messages 515 Feb 24, 2023 #1 I wish to use a recordset call with SQL to return all records for the current month/year... can you advise on the parameters to Format to achieve this please..?
I wish to use a recordset call with SQL to return all records for the current month/year... can you advise on the parameters to Format to achieve this please..?
C CJ_London Super Moderator Staff member Local time Today, 20:59 Joined Feb 19, 2013 Messages 17,497 Feb 24, 2023 #2 in sql the criteria would be something like WHERE recordDate > (date-day(date)) and recordDate<dateadd('m',1,date-day(date))+1
in sql the criteria would be something like WHERE recordDate > (date-day(date)) and recordDate<dateadd('m',1,date-day(date))+1
GUIDO22 Registered User. Local time Today, 20:59 Joined Nov 2, 2003 Messages 515 Feb 24, 2023 #3 I came up with this ... (Month(Now())=MONTH(SaleDate) AND Year(Now())=YEAR(SaleDate))
Gasman Enthusiastic Amateur Local time Today, 20:59 Joined Sep 21, 2011 Messages 16,862 Feb 24, 2023 #4 GUIDO22 said: I came up with this ... (Month(Now())=MONTH(SaleDate) AND Year(Now())=YEAR(SaleDate)) Click to expand... That would also work?
GUIDO22 said: I came up with this ... (Month(Now())=MONTH(SaleDate) AND Year(Now())=YEAR(SaleDate)) Click to expand... That would also work?
GUIDO22 Registered User. Local time Today, 20:59 Joined Nov 2, 2003 Messages 515 Feb 24, 2023 #5 Yes, works fine..
E ebs17 Well-known member Local time Today, 21:59 Joined Feb 7, 2020 Messages 2,212 Feb 24, 2023 #6 SQL: SELECT * FROM TableX WHERE DateTimeField >= DateSerial(Year(Date()), Month(Date()), 1) AND DateTimeField < DateSerial(Year(Date()), Month(Date()) + 1, 1) This also allows you to use an index that may exist. This works faster - sometimes you need speed.
SQL: SELECT * FROM TableX WHERE DateTimeField >= DateSerial(Year(Date()), Month(Date()), 1) AND DateTimeField < DateSerial(Year(Date()), Month(Date()) + 1, 1) This also allows you to use an index that may exist. This works faster - sometimes you need speed.
C CJ_London Super Moderator Staff member Local time Today, 20:59 Joined Feb 19, 2013 Messages 17,497 Feb 24, 2023 #7 my suggestion in post #2 also utilises indexing
E ebs17 Well-known member Local time Today, 21:59 Joined Feb 7, 2020 Messages 2,212 Feb 24, 2023 #8 This is correct, because no calculation is applied to the table field and there is no NOT or <> in the comparison. However, in SQL Date must be used as Date() (=> function). Date without brackets would be interpreted as unknown variable.
This is correct, because no calculation is applied to the table field and there is no NOT or <> in the comparison. However, in SQL Date must be used as Date() (=> function). Date without brackets would be interpreted as unknown variable.
C CJ_London Super Moderator Staff member Local time Today, 20:59 Joined Feb 19, 2013 Messages 17,497 Feb 24, 2023 #9 hmm verified it in the immediate window - sql will add the () automatically. But agree, poor presentation on my account
hmm verified it in the immediate window - sql will add the () automatically. But agree, poor presentation on my account
E ebs17 Well-known member Local time Today, 21:59 Joined Feb 7, 2020 Messages 2,212 Feb 24, 2023 #10 What you should also pay attention to: A DateTime field can contain time components, which would therefore also have to be taken into account. Code: ? Date - Day(Date) 31.01.2023 Here, practically the whole day before the current month would be included in the filter.
What you should also pay attention to: A DateTime field can contain time components, which would therefore also have to be taken into account. Code: ? Date - Day(Date) 31.01.2023 Here, practically the whole day before the current month would be included in the filter.
Gasman Enthusiastic Amateur Local time Today, 20:59 Joined Sep 21, 2011 Messages 16,862 Feb 24, 2023 #11 CJ_London said: in sql the criteria would be something like WHERE recordDate > (date-day(date)) and recordDate<dateadd('m',1,date-day(date))+1 Click to expand... I kept getting 'expected expression' for the last criteria when using it in the immediate window? Changed 'm' to "m" and it worked as I expected?
CJ_London said: in sql the criteria would be something like WHERE recordDate > (date-day(date)) and recordDate<dateadd('m',1,date-day(date))+1 Click to expand... I kept getting 'expected expression' for the last criteria when using it in the immediate window? Changed 'm' to "m" and it worked as I expected?