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 2008 Forums
 Other SQL Server 2008 Topics
 Help with the most recent date
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mjimenezh
Yak Posting Veteran

Mexico
52 Posts

Posted - 10/03/2013 :  16:19:13  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3323 Posts

Posted - 10/03/2013 :  16:36:29  Show Profile  Reply with Quote
;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

Mexico
52 Posts

Posted - 10/03/2013 :  17:06:32  Show Profile  Reply with Quote
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

;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

Mexico
52 Posts

Posted - 10/03/2013 :  17:10:52  Show Profile  Reply with Quote
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
  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