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)
 seperate integer from hexadecimal and then add 1

Author  Topic 

er.bhupinder53
Starting Member

13 Posts

Posted - 2011-07-06 : 19:57:52
Hi guys,

I have a result set like
col1 : 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 like

with cte as
(
select i=1
union all
select i = i + 1 from cte where i<9
)
select t1.col1, col2 = max(substring(t1.col1,t2.i+4,1))+1
from tbl t1
cross join cte t2
group 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.
Go to Top of Page
   

- Advertisement -