T-SQL - What is the output of the statement

  • Comments posted to this topic are about the item T-SQL - What is the output of the statement

  • It's 6th October already? What was I drinking last night?! :rolleyes:

  • I ran the following:

    create table tb_user

    (name varchar(30));

    insert into tb_user

    values ('Assis Marques new');

    UPDATE a

    SET Name = 'Assis Marques new'

    OUTPUT Inserted.Name, Deleted.Name

    FROM tb_User a

    WHERE Name = 'Assis Marques';

    select * from tb_user;

    The result is:

    Assis Marques new

    Since the where clause is false nothing is updated, there for Output is also null.

    Raymond Laubert
    Exceptional DBA of 2009 Finalist
    MCT, MCDBA, MCITP:SQL 2005 Admin,
    MCSE, OCP:10g

  • Your initial insert statement is incorrect.

    "Assume you have a SQLServer2005 database and that the table "tb_User" contains the user 'Assis Marques'"

    You need to modify the initial insert to be this statement:

    INSERT INTO tb_User(Name)

    VALUES('Assis Marques');

    Cheers,

    Brian

  • You know what they say, read the whole question.

  • Hmm. I got my point, but two *columns* ???

    Two rows would have been better perhaps?

    Or even two lots of one row?

    Oh well.

  • Interesting, I didn't know you could do that.

  • Just goes to show that your mind sees what it wants to see. I read this three times before posting just to make sure I wasn't missing something. I still missed it.

    Thanks for catching it and letting me know.

    Raymond Laubert
    Exceptional DBA of 2009 Finalist
    MCT, MCDBA, MCITP:SQL 2005 Admin,
    MCSE, OCP:10g

  • Oh great - even in future, I got the question wrong - great motivation!!! 😀

    Farhan F. Sabzaali
    PMP, MCP, MCDBA, MCSA, MCSE

  • Ray Laubert (6/17/2009)


    Just goes to show that your mind sees what it wants to see. I read this three times before posting just to make sure I wasn't missing something. I still missed it.

    Thanks for catching it and letting me know.

    That's why they don't let us test our own code.

  • Ray Laubert (6/17/2009)


    Thanks for catching it and letting me know.

    No worries. The answer was still clearly discernible from the information given.

    🙂

  • Nice question!!!

  • crussell (6/17/2009)


    I tested it on an existing test database table and immediately got an error because I had a trigger on the table. Using a table without a trigger gave me the kind of results intended.

    There also can't be any CHECK constaints on the table, and it can't be either end of a FOREIGN KEY relationship.

    Paul

  • :-)That is an incredibly useful bit of code.

    Thank You

  • I didn't even get a chance to read the question and it says I got it right. Read ahead buffer acting up????



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

Viewing 15 posts - 1 through 15 (of 19 total)

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