How to set Empty value for first row third column value.

  • Hi ,

    I want to set the first row third column (e-mail) value as empty. How do i handle?? Can anyone help on this??

    Expected output

    NAME-----PHONE-------EMAIL

    A---------3333---------

    B---------4444---------XXX

  • UPDATE myTable

    SET email = '' -- or NULL

    WHERE name = 'A';

    Before you run this, you really need to read up on UPDATE and INSERT in books online. Also, if this is an adhoc request that you are going to run one time (or infrequently) - then you want to wrap it in a transaction just in case...

    BEGIN TRANSACTION;

    UPDATE ...

    ROLLBACK TRANSACTION;

    You can then run the above and validate that the correct number of rows have been updated. You could also add SELECT statements to return the updated data (before the rollback) so you can validate the data was updated correctly.

    When you are satisfied that the code is working as you expect, change the ROLLBACK to a COMMIT and run it. The COMMIT will make the change permanent and viewable by everyone.

    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

  • thundersplash845 (5/31/2011)


    Hi ,

    I want to set the first row third column (e-mail) value as empty. How do i handle?? Can anyone help on this??

    Expected output

    NAME-----PHONE-------EMAIL

    A---------3333---------

    B---------4444---------XXX

    I've just gotta ask... Why do you want to do this only to the "first"row?

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

  • if you are doing this in Reporing services then i would be more inclined to do this in the report/dataset rather than changes,

    you could write an expression either in the dataset or report to handle the same logic that is outlined above, and this would leave the source data intact

Viewing 4 posts - 1 through 3 (of 3 total)

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