STRING_SPLIT()

  • Raghavender Chavva - Monday, July 9, 2018 8:26 AM

    When I executed this code in SQL Server 2016, below is the error:

    Procedure expects parameter 'separator' of type 'nchar(1)/nvarchar(1)'

    Precisely why all of the discussion above says that the question lists an incorrect answer. πŸ˜‰

    --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)

  • I suspect a lot of people on here have their own split functions that behave just like the purported correct answer, I assumed the question was designed to show the short comings of String_Split().
    How many people are still using homegrown (or "Google Found") split functions whilst eagerly awaiting the next version of String_Split?

  • I got the "correct" wrong answer simply because I made the faulty assumption that SQL Server would simply use the 1st character and "shave off" any subsequent characters... like it does everywhere else...

    DECLARE
        @cars    VARCHAR (200) = 'Porsche, Ferrari, Bentley, Jaguar,Range Rover',
        @delim NCHAR (1) = N', ';

    SELECT
        value
    FROM
        STRING_SPLIT(@cars, @delim);

    or

    DECLARE    @cars VARCHAR (200) = 'Porsche, Ferrari, Bentley, Jaguar,Range Rover';

    SELECT * FROM dbo.DelimitedSplit8K(@cars, ', ') dsk;

    Way to be consistent Microsoft... πŸ™

  • Ah, ticked the wrong checkbox on my side. My apologies. Awarding back points.

  • I couldn't, for the life, of me work out why Jeff and Eirikur had a problem with the question yesterday, as I answered it on my phone. Turns out that the space is practically invisible on my phones browser, as the font loses its fixed width. >_<

    Thom~

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

  • I didn't know how to showcase the space in there well. Maybe I need to add a note that the parameter is comma, space?

  • Steve Jones - SSC Editor - Monday, July 9, 2018 10:04 AM

    I didn't know how to showcase the space in there well. Maybe I need to add a note that the parameter is comma, space?

    It's fine on PC, which is more likely what people will; be viewing it on; it just making (almost) invisible on my Pixel.

    Thom~

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

  • Thom A - Monday, July 9, 2018 9:40 AM

    I couldn't, for the life, of me work out why Jeff and Eirikur had a problem with the question yesterday, as I answered it on my phone. Turns out that the space is practically invisible on my phones browser, as the font loses its fixed width. >_<

    He he, didn't have a problem with the question πŸ˜‰
    😎
    Questions are never a problem, answers, on the other hand, can be problematic.

  • Reading through the discussion i'm glad i only got to answer this today (still trying to catch up after the week away)....

    ____________________________________________
    Space, the final frontier? not any more...
    All limits henceforth are self-imposed.
    β€œlibera tute vulgaris ex”

Viewing 9 posts - 16 through 23 (of 23 total)

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