MAX DATE IN QUERY

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

MAX DATE IN QUERY

Post by sal21 »

SQL = "Select * From TAB WHERE AGG=#15/09/2010#"

Instead the fixed date is possible to filterd the max date into the filed AGG and store the value of max date in a variable?

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: MAX DATE IN QUERY

Post by HansV »

You could use

SQL = SELECT Max(AGG) As MaxAGG FROM TAB"

Open a recordset on this SQL string, let's say you name it RS. Then use

MyVar = RS!MaxAGG

to store the value in a variable.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

Re: MAX DATE IN QUERY

Post by sal21 »

HansV wrote:You could use

SQL = SELECT Max(AGG) As MaxAGG FROM TAB"

Open a recordset on this SQL string, let's say you name it RS. Then use

MyVar = RS!MaxAGG

to store the value in a variable.
But your query select also all records whit the filter MaxAGG?
i have used * param in my old query...

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: MAX DATE IN QUERY

Post by HansV »

Sorry, I don't understand. Do you want to select the entire record or do you want to get the maximum value of AGG?
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

Re: MAX DATE IN QUERY

Post by sal21 »

HansV wrote:Sorry, I don't understand. Do you want to select the entire record or do you want to get the maximum value of AGG?
I need to extract all records from tab where the max date are preesnt in AGG

User avatar
HansV
Administrator
Posts: 78493
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: MAX DATE IN QUERY

Post by HansV »

OK, try this then:

SQL = "SELECT * FROM TAB WHERE AGG=(SELECT Max(AGG) FROM TAB)"
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

Re: MAX DATE IN QUERY

Post by sal21 »

HansV wrote:OK, try this then:

SQL = "SELECT * FROM TAB WHERE AGG=(SELECT Max(AGG) FROM TAB)"
I lo** you!
:thankyou: