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
 Transact-SQL (2008)
 cumulative last final record needed

Author  Topic 

kond.mohan
Posting Yak Master

213 Posts

Posted - 2013-07-11 : 07:16:15
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

52326 Posts

Posted - 2013-07-11 : 07:20:07
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

213 Posts

Posted - 2013-07-11 : 08:12:11
hi vishak ,

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

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-07-11 : 08:15:01
[code]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;[/code]
Go to Top of Page
   

- Advertisement -