CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: SQL Help !!!!!

  1. #1
    Join Date
    May 1999
    Posts
    41

    SQL Help !!!!!

    Hi,
    I am trying to get the latest report date and the relevant well no from a group of wells.I have the following SQL.

    SELECT Max(DTE_UPDATED) , WELL FROM TEST_DATA
    WHERE (((WELL)=1 Or (WELL)=2 Or (WELL)=3 Or (WELL)=4));


    I get an erro message which says
    "You tried to execute a query that doesn't include the specified expression as part of an aggregate function or grouping."

    If I just get the report date (i.e. w/o the well) it works fine. But I want the latest report date for this group of wells as well as the relavent well no for the latest report (i.e. it culd be 1,2,3 or 4)

    Can somone point out the error in my SQL

    Cheers

    Vijja



  2. #2
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: SQL Help !!!!!

    I believe that you cannot use MAX function with Fields (like WELL) together

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

  3. #3
    Join Date
    Feb 2000
    Location
    Ireland
    Posts
    808

    Re: SQL Help !!!!!

    Change your SQL to
    SELECT Max(DTE_UPDATED) , WELL FROM TEST_DATA
    WHERE (((WELL)=1 Or (WELL)=2 Or (WELL)=3 Or (WELL)=4)) GROUP BY WELL;





  4. #4
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: SQL Help !!!!!


    SELECT Well, Max(DTE_UPDATED)
    From TEST_DATE
    Where Well IN (1,2,3,4)
    Group By Well


    That should do the trick.

    HTH,
    D.

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured