syntax question-maybe easy and light

Posted on 2004-11-03
Last Modified: 2010-03-19
I am trying to get to run this...

Select   RegularRate, OTRate, max(effectivedate)  from AssignToLookup where

but it is giving me an error saying it is part of aggregrate function or something like that.

All I need to get is the highest date entered for that particular title.
Question by:zachvaldez
    LVL 11

    Assisted Solution

    Remove the other 2 fields from your querry and it should work...

    Select   max(effectivedate) Maxeffectivedate  from AssignToLookup where

    If you want the other fields also you need to group by them or include them in aggregate functions also
    LVL 5

    Accepted Solution

    If you need the other columns, as rdnummer pointed out,

    Select   RegularRate, OTRate, max(effectivedate)  from AssignToLookup where
    group by RegularRate, OTRate

    Author Comment

    Thanks, I have to split the points..
    LVL 11

    Expert Comment

    If you group by the other fields then the result might not be what you expect...

    For example if there are several records for one TitleID in the AssignToLookup table you wont get what you asked for... You will "only" get the "Highest effectivedate for each TitleID where all the fields ( RegularRate, OTRate) have the same value..

    In an example this would mean....

     RegularRate, OTRate, effectivedate , (TitleID is same for all records so i will skip it here)
    12, 20, 1.1.04
    12, 20 , 1.9.03
    13,30 , 1.5.04

    You will revieve 2!!! results...
    12, 20, 1.1.04
    13,30 , 1.5.04


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    PRTG Network Monitor: Intuitive Network Monitoring

    Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

    Introduction In my previous article ( I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
    Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
    Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
    Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now