SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Max date
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

peace
Constraint Violating Yak Guru

415 Posts

Posted - 05/01/2013 :  04:10:25  Show Profile  Reply with Quote
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

India
690 Posts

Posted - 05/01/2013 :  04:48:11  Show Profile  Send ahmeds08 a Yahoo! Message  Reply with Quote
select MAX(date1),sum(amount),ID from table
group by id


mohammad.javeed.ahmed@gmail.com

Edited by - ahmeds08 on 05/01/2013 04:48:30
Go to Top of Page

peace
Constraint Violating Yak Guru

415 Posts

Posted - 05/01/2013 :  04:55:20  Show Profile  Reply with Quote
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

India
690 Posts

Posted - 05/01/2013 :  05:02:32  Show Profile  Send ahmeds08 a Yahoo! Message  Reply with Quote
why do you want to convert the date column?

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

peace
Constraint Violating Yak Guru

415 Posts

Posted - 05/01/2013 :  05:05:29  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

4614 Posts

Posted - 05/01/2013 :  11:14:29  Show Profile  Reply with Quote
What is the datatype of your date column?
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000