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
 General SQL Server Forums
 New to SQL Server Programming
 Select date for Inv# that is 10th from the end.

Author  Topic 

grandfso
Starting Member

2 Posts

Posted - 2011-03-10 : 07:32:47
Hi,

I have a table like this one. What I need to do select the SCHEDULED DATE which is 10th from the end for each Inv#... Have no clue how to do this.
I appreciate this is easy for more experienced SQL professionals however for me as a newbie this is an obstacle I am unable overcome at the moment. Any help appreciated.


Inv# SID SCHEDULED DATE ACTUAL DATE
10000 1 2004-11-07 00:00:00 2004-11-22 00:00:00
10000 2 2004-12-07 00:00:00 2004-12-10 00:00:00
10000 3 2005-01-07 00:00:00 2005-01-12 00:00:00
10000 4 2005-02-07 00:00:00 2005-02-11 00:00:00
10000 5 2005-03-07 00:00:00 2005-03-16 00:00:00
10000 6 2005-04-07 00:00:00 2005-04-15 00:00:00
10000 7 2005-05-07 00:00:00 2005-05-17 00:00:00
10000 8 2005-06-07 00:00:00 2005-07-25 00:00:00
10000 9 2005-07-07 00:00:00 2005-08-17 00:00:00
10000 10 2005-08-07 00:00:00 2005-08-17 00:00:00
10000 11 2005-09-07 00:00:00 2005-09-12 00:00:00
10000 12 2005-10-07 00:00:00 2005-11-16 00:00:00
10000 13 2005-11-07 00:00:00 2005-11-16 00:00:00
10000 14 2005-12-07 00:00:00 2006-02-28 00:00:00
10000 15 2006-01-07 00:00:00 2006-03-31 00:00:00
10000 16 2006-02-07 00:00:00 2006-03-31 00:00:00
10000 17 2006-03-07 00:00:00 2006-05-02 00:00:00
10000 18 2006-04-07 00:00:00 2006-06-30 00:00:00
10000 19 2006-05-07 00:00:00 2006-06-30 00:00:00
10000 20 2006-06-07 00:00:00 2006-07-26 00:00:00
10000 21 2006-07-07 00:00:00 2006-08-28 00:00:00
10000 22 2006-08-07 00:00:00 2006-08-28 00:00:00
10000 23 2006-09-07 00:00:00 2006-10-05 00:00:00
10000 24 2006-10-07 00:00:00 2006-10-05 00:00:00
10000 25 2006-11-07 00:00:00 2006-10-25 00:00:00
10000 26 2006-12-07 00:00:00 2006-12-07 00:00:00
10000 27 2007-01-07 00:00:00 2006-12-07 00:00:00
10000 28 2007-02-07 00:00:00 2006-12-07 00:00:00
10000 29 2007-03-07 00:00:00 2007-01-25 00:00:00
10000 30 2007-04-07 00:00:00 2007-01-25 00:00:00
10000 31 2007-05-07 00:00:00 2007-02-28 00:00:00
10000 32 2007-06-07 00:00:00 2007-02-28 00:00:00
10000 33 2007-07-07 00:00:00 2007-03-20 00:00:00
10000 34 2007-08-07 00:00:00 2007-03-20 00:00:00
10000 35 2007-09-07 00:00:00 2007-03-20 00:00:00
10000 36 2007-10-07 00:00:00 2008-09-16 00:00:00
10001 1 2004-11-07 00:00:00 2004-11-15 00:00:00
10001 2 2004-12-07 00:00:00 2004-12-08 00:00:00
10001 3 2005-01-07 00:00:00 2005-01-18 00:00:00
10001 4 2005-02-07 00:00:00 2005-02-10 00:00:00
10001 5 2005-03-07 00:00:00 2005-03-18 00:00:00
10001 6 2005-04-07 00:00:00 2005-04-13 00:00:00
10001 7 2005-05-07 00:00:00 2005-05-16 00:00:00
10001 8 2005-06-07 00:00:00 2005-06-10 00:00:00
10001 9 2005-07-07 00:00:00 2005-07-08 00:00:00
10001 10 2005-08-07 00:00:00 2005-09-14 00:00:00
10001 11 2005-09-07 00:00:00 2005-10-28 00:00:00
10001 12 2005-10-07 00:00:00 2005-12-13 00:00:00
10001 13 2005-11-07 00:00:00 2006-10-23 00:00:00
10001 14 2005-12-07 00:00:00 2007-02-21 00:00:00
10001 15 2006-01-07 00:00:00 2007-10-23 00:00:00
10001 16 2006-02-07 00:00:00 2008-01-22 00:00:00
10001 17 2006-03-07 00:00:00 2008-01-22 00:00:00
10001 18 2006-04-07 00:00:00 2008-02-22 00:00:00
10001 19 2006-05-07 00:00:00 2008-03-25 00:00:00
10001 20 2006-06-07 00:00:00 2008-03-25 00:00:00
10001 21 2006-07-07 00:00:00 2008-06-23 00:00:00
10001 22 2006-08-07 00:00:00 2008-08-22 00:00:00
10001 23 2006-09-07 00:00:00 2008-10-21 00:00:00
10001 24 2006-10-07 00:00:00 2008-12-22 00:00:00
10001 25 2006-11-07 00:00:00 2009-07-21 00:00:00
10001 26 2006-12-07 00:00:00 2009-09-22 00:00:00
10001 27 2007-01-07 00:00:00 2009-10-22 00:00:00
10001 28 2007-02-07 00:00:00 2009-11-24 00:00:00
10001 29 2007-03-07 00:00:00 2010-01-25 00:00:00
10001 30 2007-04-07 00:00:00 2010-03-23 00:00:00
10001 31 2007-05-07 00:00:00 2010-06-24 00:00:00
10001 32 2007-06-07 00:00:00 2010-08-24 00:00:00
10001 33 2007-07-07 00:00:00 2011-02-23 00:00:00
10001 34 2007-08-07 00:00:00 NULL
10001 35 2007-09-07 00:00:00 NULL
10001 36 2007-10-07 00:00:00 NULL
10002 1 2004-11-01 00:00:00 2004-11-08 00:00:00
10002 2 2004-12-01 00:00:00 2004-12-01 00:00:00
10002 3 2005-01-01 00:00:00 2004-12-31 00:00:00
10002 4 2005-02-01 00:00:00 2005-01-28 00:00:00
10002 5 2005-03-01 00:00:00 2005-03-03 00:00:00
10002 6 2005-04-01 00:00:00 2005-03-29 00:00:00
10002 7 2005-05-01 00:00:00 2005-04-28 00:00:00
10002 8 2005-06-01 00:00:00 2005-06-01 00:00:00
10002 9 2005-07-01 00:00:00 2005-07-09 00:00:00
10002 10 2005-08-01 00:00:00 2005-08-05 00:00:00
10002 11 2005-09-01 00:00:00 2005-10-26 00:00:00
10002 12 2005-10-01 00:00:00 2005-10-26 00:00:00
10002 13 2005-11-01 00:00:00 2005-10-26 00:00:00
10002 14 2005-12-01 00:00:00 2006-09-28 00:00:00
10002 15 2006-01-01 00:00:00 2007-06-21 00:00:00
10002 16 2006-02-01 00:00:00 2007-07-25 00:00:00
10002 17 2006-03-01 00:00:00 2008-03-27 00:00:00
10002 18 2006-04-01 00:00:00 2009-03-23 00:00:00
10002 19 2006-05-01 00:00:00 NULL
10002 20 2006-06-01 00:00:00 NULL
10002 21 2006-07-01 00:00:00 NULL
10002 22 2006-08-01 00:00:00 NULL
10002 23 2006-09-01 00:00:00 NULL
10002 24 2006-10-01 00:00:00 NULL
10002 25 2006-11-01 00:00:00 NULL
10002 26 2006-12-01 00:00:00 NULL
10002 27 2007-01-01 00:00:00 NULL
10002 28 2007-02-01 00:00:00 NULL

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-03-10 : 07:47:46
if you are using SQL 2005/2008, use the row_number() function


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-03-10 : 10:00:26
Refer this
http://beyondrelational.com/blogs/madhivanan/archive/2008/09/12/return-top-n-rows.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

grandfso
Starting Member

2 Posts

Posted - 2011-03-11 : 08:24:48
Thanks for replies,
This resultset was joined to another resultset so In the end I used Joins to get it done.

thanks and regards, Grand
Go to Top of Page
   

- Advertisement -