Home Forums SQL Server 2012 SQL Server 2012 - T-SQL Is it possible to incrementally increase a number value at the end of a varchar string? RE: Is it possible to incrementally increase a number value at the end of a varchar string?

  • Hi,

    Thanks both for your replies and help.

    Scott, That's brilliant, and has solved the puzzle. I applied it to my work example and removed this bit:

    ROW_NUMBER() over(order by AccountNumber) as row_num

    and it works perfectly. I would never have got to this solution on my own, and am new to using CROSS APPLY so this was great learning for me. I really like the way RIGHT('0' + CAST(base_value + row_num AS varchar(2)), 2) handles the segments past '09' - I wondered how to do that. Really elegant.

    GSquared, I need to learn more about Sequence Objects as I'd never heard of them before your suggestion. They're new to 2012? I'll explore and see if they can also solve the puzzle.

    Cheers both for helping me out and for giving me cool new things to learn.

    Lins