Comma Separator Delimiter

  • Hi Guys,

    I am struck with some fires logic, which i am not able to figure out 🙂

    I have a comma separator field,

    For Example, the field values is

    Annual Holiday, Annual Leave - David Hornby,

    Solution: I want to retrieve the first comma string (Annual Holiday) and remove the rest value from the field and display.

    It should be Just Annual Holiday

  • I found the solution..

    LEFT([field], CHARINDEX(',', [field]) - 1)

    :):):)

    Thanks:-):-):-):-)

  • farooq.hbs (5/14/2014)


    I found the solution..

    LEFT([field], CHARINDEX(',', [field]) - 1)

    :):):)

    Thanks:-):-):-):-)

    That will work if you are certain that your source string will ALWAYS contain at least one comma. If you cannot guarantee that then you will need to test for the presence of a comma and return the original string if there is none.

  • crmitchell (5/15/2014)


    farooq.hbs (5/14/2014)


    I found the solution..

    LEFT([field], CHARINDEX(',', [field]) - 1)

    :):):)

    Thanks:-):-):-):-)

    That will work if you are certain that your source string will ALWAYS contain at least one comma. If you cannot guarantee that then you will need to test for the presence of a comma and return the original string if there is none.

    There's no need for a great validation process, just append a comma to the field.

    LEFT([field], CHARINDEX(',', [field] + ',') - 1)

    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
  • Luis Cazares (5/15/2014)


    crmitchell (5/15/2014)


    farooq.hbs (5/14/2014)


    I found the solution..

    LEFT([field], CHARINDEX(',', [field]) - 1)

    :):):)

    Thanks:-):-):-):-)

    That will work if you are certain that your source string will ALWAYS contain at least one comma. If you cannot guarantee that then you will need to test for the presence of a comma and return the original string if there is none.

    There's no need for a great validation process, just append a comma to the field.

    LEFT([field], CHARINDEX(',', [field] + ',') - 1)

    Careful now... concatenation is what killed the cat on some of the earlier splitters. It will probably be faster to do the ISNULL/NULL IF thing to change a 0 to 8000.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden (5/15/2014)


    Luis Cazares (5/15/2014)


    crmitchell (5/15/2014)


    farooq.hbs (5/14/2014)


    I found the solution..

    LEFT([field], CHARINDEX(',', [field]) - 1)

    :):):)

    Thanks:-):-):-):-)

    That will work if you are certain that your source string will ALWAYS contain at least one comma. If you cannot guarantee that then you will need to test for the presence of a comma and return the original string if there is none.

    There's no need for a great validation process, just append a comma to the field.

    LEFT([field], CHARINDEX(',', [field] + ',') - 1)

    Careful now... concatenation is what killed the cat on some of the earlier splitters. It will probably be faster to do the ISNULL/NULL IF thing to change a 0 to 8000.

    It's good to know. I usually don't work with strings that long. I wouldn't expect this scenario to be one of those cases.

    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
  • Agreed. It's not going to matter with such short strings as those on this post. It was more of a tip just in case you need to do something similar with longer strings. I should have made that more clear.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 7 posts - 1 through 6 (of 6 total)

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