TSQL Logic help needed-- Nested IF

  • David Burrows (4/21/2011)


    Jeff Moden (4/20/2011)


    If we don't know the length, then we can force the max length for positive BIGINTs and simply remove all spaces afterwards.

    Also if you append the separator to the cast instead of prefixing, you don't need the stuff 😛

    Great idea! It also converts the totally NULL lines to empty strings which may be a benefit for additional processing.

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

  • David Burrows (4/21/2011)


    ChrisM@home (4/21/2011)


    Evolution in practice - don't you just love it 😀

    It is darn near impossible to improve on Jeff's solutions, so must make the most of it while I can 😀

    Thanks guys. :blush: Wish I could take credit for this one but Jason's suggestion is what brought this one out. 🙂

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

  • ChrisM@home (4/21/2011)


    David Burrows (4/21/2011)


    Jeff Moden (4/20/2011)


    If we don't know the length, then we can force the max length for positive BIGINTs and simply remove all spaces afterwards.

    Also if you append the separator to the cast instead of prefixing, you don't need the stuff 😛

    Evolution in practice - don't you just love it 😀

    That's why I love this place. 🙂 This particular type of problem is more common that I care to admit and I've seen all manner of code to solve it but nothing this simple. Jason's ephiphany was spot on.

    --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 (4/21/2011)


    ChrisM@home (4/21/2011)


    David Burrows (4/21/2011)


    Jeff Moden (4/20/2011)


    If we don't know the length, then we can force the max length for positive BIGINTs and simply remove all spaces afterwards.

    Also if you append the separator to the cast instead of prefixing, you don't need the stuff 😛

    Evolution in practice - don't you just love it 😀

    That's why I love this place. 🙂 This particular type of problem is more common that I care to admit and I've seen all manner of code to solve it but nothing this simple. Jason's ephiphany was spot on.

    Stop it Jeff, you're making me blush.. LOL

    Nothing remarkable here.

    Sometimes it's just best to take a step back. Just like they say "If you can't see the forest for the trees, cut the darned things down!"

    ______________________________________________________________________

    Personal Motto: Why push the envelope when you can just open it?

    If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.

    Jason L. Selburg
  • Good job Jason! (Heck, I really did like my solution, but this is so much better.)

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

Viewing 5 posts - 16 through 19 (of 19 total)

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