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 2008 Forums
 Other SQL Server 2008 Topics
 Help with the most recent date

Author  Topic 

mjimenezh
Yak Posting Veteran

81 Posts

Posted - 2013-10-03 : 16:19:13
Hi, I have a sql view and here I get all the modifications of my items ("Datakey" field), but I just need the most recent modification ("Created" field) of every item and, no all the modificacions of every item I don't know how I can get it, can you help me?

Thanks a lot

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-10-03 : 16:36:29
[code];with cte as (
select *, row_number() over( partition by Datakey order by Created DESC) as RN
from YourTable
) select * from cte where RN = 1;[/code]
Go to Top of Page

mjimenezh
Yak Posting Veteran

81 Posts

Posted - 2013-10-03 : 17:06:32
Hi James,i really appreciate your help, I made that you say but it doesn't works, I remplaced my original code :
SELECT Action,OldValue,NewValue,Created,Creator,DataKey
FROM dbo.EbcDataLog AS ed
WHERE (DataKey IS NOT NULL)

by the code that you said me but i'm still receiving two or more rows per item

quote:
Originally posted by James K

[code];with cte as (
select *, row_number() over( partition by Datakey order by Created DESC) as RN
from YourTable
) select * from cte where RN = 1;


Go to Top of Page

mjimenezh
Yak Posting Veteran

81 Posts

Posted - 2013-10-03 : 17:10:52
Hi James, it was my mistake, your code works perfect, thankyou some much.



quote:

Originally posted by James K

;with cte as (
select *, row_number() over( partition by Datakey order by Created DESC) as RN
from YourTable
) select * from cte where RN = 1;


Go to Top of Page
   

- Advertisement -