Removing commas

  • Hi,

    I have a simple statement where I am trying to remove all commas that may be in the xn_workordeld column.

    SELECT

    xn_workordeld = case replace(xn_workordeld, ',', '') as "WORKORDER LD"

    from workorder

    But I'm not having much luck ...doing something wrong.

  • krypto69 (2/5/2015)


    Hi,

    I have a simple statement where I am trying to remove all commas that may be in the xn_workordeld column.

    SELECT

    xn_workordeld = case replace(xn_workordeld, ',', '') as "WORKORDER LD"

    from workorder

    But I'm not having much luck ...doing something wrong.

    Try this:

    SELECT

    REPLACE(CAST(xn_workordeld AS VARCHAR(MAX)),',', '') AS 'WORKORDER LD'

    from workorder

  • krypto69 (2/5/2015)


    Hi,

    I have a simple statement where I am trying to remove all commas that may be in the xn_workordeld column.

    SELECT

    xn_workordeld = case replace(xn_workordeld, ',', '') as "WORKORDER LD"

    from workorder

    But I'm not having much luck ...doing something wrong.

    Two things are wrong:

    - You're asigning a column name twice. Once using the equal sign and the other using AS keyword.

    - You also have a case keyword without the complete structure.

    I'm not sure if those errors are in your real code, but if you remove them it works fine.

    WITH workorder AS(

    SELECT 'some, commas, in, here,' AS xn_workordeld

    )

    SELECT replace(xn_workordeld, ',', '') as "WORKORDER LD"

    from workorder

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • thanks guys!

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

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