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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 computed column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

craigmacca2424
Starting Member

1 Posts

Posted - 08/26/2014 :  20:49:14  Show Profile  Reply with Quote
Hi,

I have a parent to child table, (Id, ParentId, DateModified)

i need to calculate the max DateModified for any of the children, as below

Id, ParentId, DateModified, CaluclatedDateModified

1, 0, 01/01/2014, 04/01/2014
2, 1, 01/01/2014, 04/01/2014
3, 1, 01/01/2014, null --no children
4, 2, 02/01/2014, 04/01/2014
5, 4, 03/01/2014, 04/01/2014
6, 5, 04/01/2014, null --no children


gbritton
Flowing Fount of Yak Knowledge

1455 Posts

Posted - 08/27/2014 :  08:36:48  Show Profile  Reply with Quote

select parent.Id, child.ParentId, max(child.DateModified)
from parent
join child
  on parent.Id = child.ParentId
group by parent.Id, child.ParentId

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.05 seconds. Powered By: Snitz Forums 2000