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
 Transact-SQL (2008)
 cumulative last final record needed
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kond.mohan
Posting Yak Master

India
196 Posts

Posted - 07/11/2013 :  07:16:15  Show Profile  Reply with Quote
hi

i have created query using SSMS 2012. used by ctes and Temp tables.
i got the output below manner.

empno,achivasondate,%ofachivedyear,avgbudget,cumlative
12 ,4.25 ,4.25 ,6 ,6
12 ,1.31 ,5.56 ,6 ,12
12 ,0.23 ,5.79 ,6 ,18
i want see my report only final row of the cumulative data.below described way
12 ,0.23 ,5.79 ,6 ,18
is there any way to pick the the data in above manner.

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 07/11/2013 :  07:20:07  Show Profile  Reply with Quote
do you've date or a sequence number (id/rowno) field?

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

kond.mohan
Posting Yak Master

India
196 Posts

Posted - 07/11/2013 :  08:12:11  Show Profile  Reply with Quote
hi vishak ,

i have a monthyear(date field)field.and don't have a sequence number.
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3742 Posts

Posted - 07/11/2013 :  08:15:01  Show Profile  Reply with Quote
SELECT
	empno,achivasondate,[%ofachivedyear],avgbudget,cumlative
FROM
(
	SELECT *,
		ROW_NUMBER() OVER (PARTITION BY empno ORDER BY YourDateField DESC) AS RN
	FROM
	(
		YourOriginalQueryHere
	) s1
) s2 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.08 seconds. Powered By: Snitz Forums 2000