You are a T-SQL developer who needs to...

  • Comments posted to this topic are about the item You are a T-SQL developer who needs to...

  • I'm sure they're looking for an answer on this one, but my answer would be "None of the above"...

    1. All of the updates will cause some improper change to properly formatted SSN's.

    2. This type of formatting should be done in the GUI, not in the database.

    3. If no GUI is present for (2) above, then the formatting should be done in the SELECT... but never in the database.

    --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 agree with Jeff - but, just to have some fun - I would not use the 'correct' answer for this one. I would use this:

    UPDATE Employee

    SET SocialSecNumber = stuff(stuff(SocialSecNumber , 6, 0, '-'), 4, 0, '-');

    And I probably would do that just to be different 😀

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • Me too... except I'd add one thing...

    UPDATE Employee

    SET SocialSecNumber = stuff(stuff(SocialSecNumber , 6, 0, '-'), 4, 0, '-');

    WHERE SocialSecNumber NOT LIKE '%[^0-9]%'

    ... just to be on the safe side.

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

  • Of course - and probably additional checking to validate that we have 9 characters, etc...

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • The QOD can't cover every condition. It's designed in this case to see if you understand SUBSTRING rather than picking the best way to do things.

  • Heh... no problem, Steve... I know about the QOD's and the fact that, like you said, they can't cover every caveat. It's one of those questions that someone asked me on an interview test once... and I gave them the same answer as a penciled in answer after I select the "correct" answer... couldn't resist posting similar here. 😀

    The problem with testing in general is that you have to understand that you have to pick the "most" correct answer out of possibly 4 or 5 correct answers and it's not "your" most correct answer... it has to be the answer the test writer thought was most correct. I hate those types of questions... 😛

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

  • Those are the only kinds of questions we can do without an interview.

    That's why the interview is important.

  • Ha ha ha. You guys are crazy. That's a lot of "stuffing" and it's not even Thanksgiving.

  • Iwas Bornready (12/23/2015)


    Ha ha ha. You guys are crazy. That's a lot of "stuffing" and it's not even Thanksgiving.

    No, but Christmas is just around the corner, and there will be stuffing a-plenty up and down this land...

    Thomas Rushton
    blog: https://thelonedba.wordpress.com

Viewing 10 posts - 1 through 9 (of 9 total)

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