Splitting Strings Based on Patterns

  • Dwain you do not need CLR to use regex 🙂

    There is an old way to call Vbscript library

    From t-SQL code 😉

  • fregatepllada (9/12/2014)


    Dwain you do not need CLR to use regex 🙂

    There is an old way to call Vbscript library

    From t-SQL code 😉

    sp_OA???

    --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)
    Intro to Tally Tables and Functions

  • Jeff Moden (9/12/2014)


    fregatepllada (9/12/2014)


    Dwain you do not need CLR to use regex 🙂

    There is an old way to call Vbscript library

    From t-SQL code 😉

    sp_OA???

    I suspect they were talking about: http://www.sqlservercentral.com/scripts/Miscellaneous/30963/

    Either way, I don't think we can get that into an iTVF.

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • Yes, an antiquated COM way 🙂

  • Just thought I add my minimalist CTE-based tally table generator:

    declare @howmany int = 50;

    with n1(n) as (select 1 from (values (1),(1),(1),(1),(1),(1),(1),(1),(1),(1)) n(n)),

    n2(n) as (select 1 from n1, n1 n),

    n4(n) as (select 1 from n2, n2 n),

    n8(n) as (select 1 from n4, n4 n),

    N(n) as (select top(@howmany) ROW_NUMBER() over(order by (select 1)) from n8)

    select n from N

    Note that I prefer (1),(1),... to (0), (0), ... since the latter makes my eyes go funny.

    Also note that order by (select 1) works as well as order by (select null) and is shorter to write (Ok, so I'm lazy!)

    Finally, my resulting table is called N to reflect its origin in the set ℕ -- the natural numbers

    Gerald Britton, Pluralsight courses

  • g.britton (11/6/2014)


    Just thought I add my minimalist CTE-based tally table generator:

    declare @howmany int = 50;

    with n1(n) as (select 1 from (values (1),(1),(1),(1),(1),(1),(1),(1),(1),(1)) n(n)),

    n2(n) as (select 1 from n1, n1 n),

    n4(n) as (select 1 from n2, n2 n),

    n8(n) as (select 1 from n4, n4 n),

    N(n) as (select top(@howmany) ROW_NUMBER() over(order by (select 1)) from n8)

    select n from N

    Note that I prefer (1),(1),... to (0), (0), ... since the latter makes my eyes go funny.

    Also note that order by (select 1) works as well as order by (select null) and is shorter to write (Ok, so I'm lazy!)

    Finally, my resulting table is called N to reflect its origin in the set ℕ -- the natural numbers

    How's this on your eyes?

    declare @howmany int = 50;

    with n1(n) as (select $ from (values ($),($),($),($),($),($),($),($),($),($)) n(n)),

    n2(n) as (select $ from n1, n1 n),

    n4(n) as (select $ from n2, n2 n),

    n8(n) as (select $ from n4, n4 n),

    N(n) as (select top(@howmany) ROW_NUMBER() over(order by (select $)) from n8)

    select n from N

    😛

    Makes me see dollar signs.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

  • dwain.c (11/6/2014)


    How's this on your eyes?

    declare @howmany int = 50;

    with n1(n) as (select $ from (values ($),($),($),($),($),($),($),($),($),($)) n(n)),

    n2(n) as (select $ from n1, n1 n),

    n4(n) as (select $ from n2, n2 n),

    n8(n) as (select $ from n4, n4 n),

    N(n) as (select top(@howmany) ROW_NUMBER() over(order by (select $)) from n8)

    select n from N

    😛

    Makes me see dollar signs.

    I love it!

    Gerald Britton, Pluralsight courses

  • Genius!


    The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url]

    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs[/url]

Viewing 8 posts - 46 through 52 (of 52 total)

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