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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 computed column

Author  Topic 

craigmacca2424
Starting Member

1 Post

Posted - 2014-08-26 : 20:49:14
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
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-08-27 : 08:36:48
[code]
select parent.Id, child.ParentId, max(child.DateModified)
from parent
join child
on parent.Id = child.ParentId
group by parent.Id, child.ParentId
[/code]
[/code]
Go to Top of Page
   

- Advertisement -