Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Max date

Author  Topic 

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2013-05-01 : 04:10:25
Hi, How can i apply the max date and get the total amount?

date amount ID
2013-01-01 $10 12345
2013-05-05 $20 12345

I tried as below but it still return the same output as above.

Select sum(amount), ID, case when date is not null then max(date) end
from table

The result I wanted are as below:

date amount ID
2013-05-05 $30 12345

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2013-05-01 : 04:48:11
select MAX(date1),sum(amount),ID from table
group by id


mohammad.javeed.ahmed@gmail.com
Go to Top of Page

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2013-05-01 : 04:55:20
I apply the the convert to date:

max(Convert(date,date))

It still appear twice.

Is the convert apply correctly?
Go to Top of Page

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2013-05-01 : 05:02:32
why do you want to convert the date column?

mohammad.javeed.ahmed@gmail.com
Go to Top of Page

peace
Constraint Violating Yak Guru

420 Posts

Posted - 2013-05-01 : 05:05:29
i actually want to standardise the date to +8 hours.
I should use dateadd right. And also would want just the date. That's why convert the date.

Is it wrong?
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2013-05-01 : 11:14:29
What is the datatype of your date column?
Go to Top of Page
   

- Advertisement -