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 |
Silumadbor
Starting Member
2 Posts |
Posted - 2015-04-23 : 17:24:27
|
In select query, how can i limit sequence upto 5 and get result like below?Rec_ID Company Sequence#123 ABC1 1124 ABC2 2125 ABC3 3126 ABC4 4127 ABC5 5128 ABC6 1129 ABC7 2130 ABC8 3131 ABC9 4132 ABC10 5133 ABC11 1134 ABC12 2135 ABC13 3136 ABC14 4137 ABC15 5138 ABC16 1139 ABC17 2140 ABC18 3141 ABC19 4142 ABC20 5thanks,silu |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2015-04-23 : 17:32:03
|
You can use the ROW_NUMBER() function to achieve this with a CTE or a derived table.Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2015-05-07 : 06:24:07
|
One way isselect Rec_ID,Company, (row_number() over (order by object_id)+4)%5+1 as Sequence# from tableMadhivananFailing to plan is Planning to fail |
|
|
Silumadbor
Starting Member
2 Posts |
Posted - 2015-05-07 : 22:10:25
|
YOU GUYS ROCK!!! THANKS!!! |
|
|
|
|
|