Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 last record
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

srisha
Starting Member

India
38 Posts

Posted - 09/30/2013 :  06:13:17  Show Profile  Reply with Quote
show to get lase updatded record


--------------------------
BY
SRISHA

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 09/30/2013 :  06:26:24  Show Profile  Reply with Quote
Assuming you've column called lastupdated you can use logic like

SELECT TOP 1 WITH TIES * FROM Table ORDER BY LastUpdated DESC


to get all records which have greatest value of last updated date

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

marcusn25
Yak Posting Veteran

Germany
56 Posts

Posted - 10/07/2013 :  17:05:38  Show Profile  Reply with Quote
Assuming you have [LastUpdateDate] date column from CustomerTable

SELECT
*
From
(
SELECT
Row_Number ()Over (Partition by CustomerID Order By LastUpdateDate desc) AS LastUpdate
,LastUpdateDate
,CustomerID
FROM Customer
) as C
Where
C.LastUpdateDate = 1

M. Ncube
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 10/07/2013 :  23:33:58  Show Profile  Reply with Quote
quote:
Originally posted by marcusn25

Assuming you have [LastUpdateDate] date column from CustomerTable

SELECT
*
From
(
SELECT
Row_Number ()Over (Partition by CustomerID Order By LastUpdateDate desc) AS LastUpdate
,LastUpdateDate
,CustomerID
FROM Customer
) as C
Where
C.LastUpdateDate = 1

M. Ncube


This will not return all records if there are multiple ones existing for the same maximum LastUpdateDate value

this tweak will make it work though!

SELECT
*
From
(
SELECT
			 Dense_Rank ()Over (Partition by CustomerID Order By LastUpdateDate desc) AS LastUpdate
			,LastUpdateDate
			,CustomerID
FROM Customer 
) as C
Where 
			C.LastUpdate = 1


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

marcusn25
Yak Posting Veteran

Germany
56 Posts

Posted - 10/10/2013 :  19:29:30  Show Profile  Reply with Quote
Yes, you are right

M. Ncube
Go to Top of Page
  Previous Topic Topic Next 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.08 seconds. Powered By: Snitz Forums 2000