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 |
|
er.bhupinder53
Starting Member
13 Posts |
Posted - 2011-07-06 : 19:57:52
|
| Hi guys,I have a result set likecol1 : ABC123456789, ABC789456123, ABD456789123, ABD000123456 and so on... (NOTE: ABC and ABD prefix will remain the same whereas the numerical value changes for all rows.(9 digits constant)) Now I want to take the maximum numerical value and add 1 to it and put that in column 2 with ABE prefix for all rows and for next row I want the same thing, find highest and add 1. Kindly help me writing a query.Thanks |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-07-06 : 20:03:51
|
| something likewith cte as(select i=1union allselect i = i + 1 from cte where i<9)select t1.col1, col2 = max(substring(t1.col1,t2.i+4,1))+1from tbl t1cross join cte t2group by t1.col1==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|