Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 23rd, 2005, 10:22 PM
Authorized User
 
Join Date: Dec 2004
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem using query to obtain max mth

Dear all, I have problems selecting current maximum date for current month that has been keyed in for the items. I'm unable to select the most current date.

I have to list the items of current month out under the if condition loop, as each item may hold 2 dates for the mth, so i have to select the most current mth entry date.


Dim maxM
query_maxM = "SELECT MAX(MONTH(m_date)) AS MAXM FROM DatePart where MAX(MONTH(m_date))=MONTH(now)"
Set rs_maxM = Server.CreateObject("ADODB.Recordset")
Set rs_maxM = conn.Execute(query_maxM)
maxM = rs_maxM("MAXM")

if month(now)= MAX(MONTH(maxM)) then


I actually have an error on the highlighted line:
Cannot have aggregate function in WHERE clause (month(MAX(m_date))=month(now())).
Will someone out there pls help me solve the query problem asap. Thanks so much!

 
Old January 24th, 2005, 01:30 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

Please try:

query_maxM = "SELECT MAX(MONTH(m_date)) AS MAXM FROM DatePart having MAX(MONTH(m_date))= MONTH(getDate())"

Om Prakash
 
Old January 24th, 2005, 10:27 PM
Authorized User
 
Join Date: Dec 2004
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi thanks om_prakash,

I managed to solve it using shorter query:

query_maxM = "SELECT MAX(m_date) AS MAXM FROM DatePart"
Set rs_maxM = Server.CreateObject("ADODB.Recordset")
Set rs_maxM = conn.Execute(query_maxM)
maxM = rs_maxM("MAXM")

if month(now) = month(maxM) then

Thanks for the help!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Aggregate function MAX creating problem..? Manu SQL Language 4 May 30th, 2006 04:41 AM
Is it possible to obtain the windows login? sswingle Classic ASP Basics 8 April 24th, 2006 10:01 PM
Problem with displaying ID when finding max or min marcin2k Access VBA 1 October 3rd, 2005 07:42 AM
MAX Query zaeem Classic ASP Databases 1 April 12th, 2005 03:16 AM
Query String Too Long....Max Length Error Message phungleon Classic ASP Databases 14 May 28th, 2004 12:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.