syntax question-maybe easy and light

I am trying to get to run this...

Select   RegularRate, OTRate, max(effectivedate)  from AssignToLookup where
TitleID=@TitleID

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.
zachvaldezAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Select   max(effectivedate) Maxeffectivedate  from AssignToLookup where
TitleID=@TitleID


If you want the other fields also you need to group by them or include them in aggregate functions also
0
svidCommented:
If you need the other columns, as rdnummer pointed out,


Select   RegularRate, OTRate, max(effectivedate)  from AssignToLookup where
TitleID=@TitleID
group by RegularRate, OTRate
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zachvaldezAuthor Commented:
Thanks, I have to split the points..
0
rdrunnerCommented:
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

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.