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.
| Author |
Topic |
|
pmotewar
Yak Posting Veteran
62 Posts |
Posted - 2009-11-03 : 04:28:08
|
Hello all,following are my table data Sr. No Year1 20032 20043 20054 20065 20076 20087 20098 20109 201110 201211 201312 201413 201514 201615 201716 201817 201918 202019 202120 202221 202322 202423 202524 202625 202726 202827 202928 203029 2031and i want output like followSr. No Year1 20032 20083 20134 20185 20236 2028 i want to delete years column records where i want to delete those records which is multiple of 5 means if min(year) is 2003 then first year should be 2003 and next year will be 2003 + 5 = 2008 , next will be 2008 + 5 =2013 like thathow can i do thatPankaj |
|
|
Ifor
Aged Yak Warrior
700 Posts |
Posted - 2009-11-03 : 05:02:45
|
Use a number/tally table:SELECT ROW_NUMBER() OVER (ORDER BY T.[Year]) AS SrNo ,T.[Year]FROM YourTable T CROSS JOIN ( SELECT MIN(Year) AS MinYear FROM YourTable ) D JOIN master.dbo.spt_values N ON T.[Year] = D.MinYear + (N.Number * 5) AND N.[Type] = 'P' |
 |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-11-03 : 05:07:00
|
| delete from #temp where s_no in(select s_nofrom #temp where (year_no-(select min(year_no) from #temp))%5>0)Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
pmotewar
Yak Posting Veteran
62 Posts |
Posted - 2009-11-03 : 05:11:34
|
quote: Originally posted by senthil_nagore delete from #temp where s_no in(select s_nofrom #temp where (year_no-(select min(year_no) from #temp))%5>0)
Thank you very much.Pankaj |
 |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-11-03 : 05:16:28
|
quote: Originally posted by pmotewar
quote: Originally posted by senthil_nagore delete from #temp where s_no in(select s_nofrom #temp where (year_no-(select min(year_no) from #temp))%5>0)
Thank you very much.Pankaj
Welcome Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
|
|
|