replacing values in one column with null values

  • I have a table in my sql server 2005 database where I need to replace all the values in one particular column with null values.

    the column excepts NULL values and is currently populated with email addresses. I need to programatically replace all of the email addresses with a NULL Value.

    Short of exporting the table, removing the email addresses and reimporting the data into the table, how can I do this with T-SQL?

  • is this as simple as an update?

    update yourTable

    set yourCol = Null

    or am i missing something?

  • Hi as per the information provided by you, just a simple update will make all the values as null

    update table set email=null

    but not sure what exactly your requirement is, may be its not this much simple.

    🙂

  • I think instead of making us guess its would better to post your DDL with some sample data and your desired output. 🙂

  • Assuming that your question is a serious need for assistance. Try this code

    CREATE TABLE Atable(Id INT IDENTITY(1,1),EmailAdd VARCHAR(100))

    INSERT INTO Atable

    SELECT 'myaddress.gamail.com'

    GO 10 --Add 10 records

    --Check that EmailAdd column does not have Null value

    SELECT * FROM Atable

    UPDATE Atable SET EmailAdd = NULL

    --Verify result

    SELECT * FROM Atable

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • Thank you! The DDL

    Create table dbo.TS_USERS (

    TS_ID int not null,

    TS_LOGINID VARCHAR(64) null,

    TS_NAME VARCHAR(64) null,

    TS_EMAIL VARCHAR(128) null,

    Current results

    TS_IDTS_LOGINIDTS_NAME TS_EMAIL

    5login1 User1 user1@email.org

    7login2 user2 user2@email.org

    8login3 user3 user3@email.org

    desired results

    TS_IDTS_LOGINIDTS_NAME TS_EMAIL

    5login1 User1

    7login2 user2

    8login3 user3

  • Update dbo.TS_USERS SET TS_EMAIL = NULL worked! Such a simple thing! Thank you for the help!

  • Glad to be of assistance. Thanks for your reply

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

Viewing 8 posts - 1 through 7 (of 7 total)

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