Update question

  • Im new to SqlServer I was wondering if you had a record with a field that is an Integer which allows null and has a value of 1 can you do an Update Statement on that record and set that field to null

  • As long as it allows NULLs, yes.

    Jared
    CE - Microsoft

  • Thanks for you're quick response the reason why I asked is because I have a cte of posts and it checks if the parentId is null and loops through the table of related posts. Then if i wanted to move a thread to another forum I wanted to be able to update the parentID to null so it becomes the root thread

  • kirkdm01 (1/23/2012)


    Im new to SqlServer I was wondering if you had a record with a field that is an Integer which allows null and has a value of 1 can you do an Update Statement on that record and set that field to null

    Yes, but the syntax is a bit weird: you need to write = NULL...

    DECLARE @test-2 TABLE (column1 integer NULL);

    INSERT @test-2

    (column1)

    VALUES

    (100),

    (200),

    (300);

    SELECT * FROM @test-2;

    UPDATE @test-2

    SET column1 = NULL

    WHERE column1 = 200;

    SELECT * FROM @test-2;

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

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