Replace Character

  • Hi,

    I have 1 field of computer numbers look like below:

    xxx_001

    xxx_002

    xxx_003

    ......

    I would like to replace the underscore with a dash like:

    xxx-001

    xxx-002

    xxx-003

    .....

    I played with REPLACE but can't get it works. Please help.

    Thx.

  • Try this out:

    create table x(x char(10))

    insert into x values('xxx_001')

    insert into x values('xxx_002')

    insert into x values('xxx_003')

    update x

    set x = replace(x,'_','-')

    select * from x

    drop table x

    Gregory Larsen, DBA

    If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples

    Gregory A. Larsen, MVP

  • works like a charm.

    thx.

  • Just one off the wall observation: It looks like you may have a column that is not fully decomposed if your prefix and suffix are treated independently.

    Maybe you need a column the XXX and the nnnn parts and view that combines these two columns into one for display purposes.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply