Seperate values in one column

  • Hi I am new to sql server

    I want to seperate one column which has multiple data seperated by column, do some operations and put the value back as it was before.

    Any idea ?

  • I'vlm afraid I don't understand what you mean here by that you have 1 column separated by columns. Can you try to explain what you mean in more detail?

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • bharat.radhakrishnen - Thursday, June 21, 2018 6:34 PM

    Hi I am new to sql server

    I want to seperate one column which has multiple data seperated by column, do some operations and put the value back as it was before.

    Any idea ?

    If your question has a typo and you mean "one column which has multiple data seperated by colon" I guess you need to take a look at this link to split the data based on a fixed separator.

    ** Don't mistake the ‘stupidity of the crowd’ for the ‘wisdom of the group’! **
  • HanShi - Friday, June 22, 2018 4:41 AM

    bharat.radhakrishnen - Thursday, June 21, 2018 6:34 PM

    Hi I am new to sql server

    I want to seperate one column which has multiple data seperated by column, do some operations and put the value back as it was before.

    Any idea ?

    If your question has a typo and you mean "one column which has multiple data seperated by colon" I guess you need to take a look at this link to split the data based on a fixed separator.

    If they do need a string splitter, they might be better using STRING_SPLIT. They are using SQL Server 2017 after all. I'm not saying that Jeff's function isn't good (it's a great piece of kit), however, unless you do need to ordinal position, then they might find better performance from STRING_SPLIT, and it also supports more than 8000/4000 characters.

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • Thom A - Friday, June 22, 2018 4:51 AM

    HanShi - Friday, June 22, 2018 4:41 AM

    bharat.radhakrishnen - Thursday, June 21, 2018 6:34 PM

    Hi I am new to sql server

    I want to seperate one column which has multiple data seperated by column, do some operations and put the value back as it was before.

    Any idea ?

    If your question has a typo and you mean "one column which has multiple data seperated by colon" I guess you need to take a look at this link to split the data based on a fixed separator.

    If they do need a string splitter, they might be better using STRING_SPLIT. They are using SQL Server 2017 after all. I'm not saying that Jeff's function isn't good (it's a great piece of kit), however, unless you do need to ordinal position, then they might find better performance from STRING_SPLIT, and it also supports more than 8000/4000 characters.

    Absolutely agreed.  Unless you need the ordinal position (I can't believe MS left that out) or you need a NULL to return if you pass it a NULL, STRING_SPLIT is the way to go.

    --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 - Friday, June 22, 2018 7:08 AM

    Absolutely agreed.  Unless you need the ordinal position (I can't believe MS left that out) or you need a NULL to return if you pass it a NULL, STRING_SPLIT is the way to go.

    You could use OUTER APPLY instead of CROSS APPLY if you know you might/could be using NULL for the input parameter for STRING_SPLIT. That would still work.

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • Thom A - Friday, June 22, 2018 4:51 AM

    HanShi - Friday, June 22, 2018 4:41 AM

    bharat.radhakrishnen - Thursday, June 21, 2018 6:34 PM

    Hi I am new to sql server

    I want to seperate one column which has multiple data seperated by column, do some operations and put the value back as it was before.

    Any idea ?

    If your question has a typo and you mean "one column which has multiple data seperated by colon" I guess you need to take a look at this link to split the data based on a fixed separator.

    If they do need a string splitter, they might be better using STRING_SPLIT. They are using SQL Server 2017 after all. I'm not saying that Jeff's function isn't good (it's a great piece of kit), however, unless you do need to ordinal position, then they might find better performance from STRING_SPLIT, and it also supports more than 8000/4000 characters.

    The original post specifically said they would need to operate on the pieces and put it back together, so I have to presume that means they'll have a reasonable likelihood of needing the ordinal position in order to be able to reassemble the pieces.

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

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

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