June 16, 2009 at 11:44 pm
Comments posted to this topic are about the item T-SQL - What is the output of the statement
June 17, 2009 at 5:24 am
It's 6th October already? What was I drinking last night?! :rolleyes:
June 17, 2009 at 5:33 am
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
June 17, 2009 at 6:33 am
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
June 17, 2009 at 6:47 am
You know what they say, read the whole question.
June 17, 2009 at 7:03 am
Hmm. I got my point, but two *columns* ???
Two rows would have been better perhaps?
Or even two lots of one row?
Oh well.
June 17, 2009 at 7:34 am
Interesting, I didn't know you could do that.
June 17, 2009 at 7:35 am
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
June 17, 2009 at 7:37 am
Oh great - even in future, I got the question wrong - great motivation!!!
Farhan F. Sabzaali
PMP, MCP, MCDBA, MCSA, MCSE
June 17, 2009 at 7:39 am
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.
June 17, 2009 at 7:46 am
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.
June 17, 2009 at 1:01 pm
Nice question!!!
June 17, 2009 at 2:48 pm
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
October 6, 2009 at 4:39 am
:-)That is an incredibly useful bit of code.
Thank You
October 6, 2009 at 8:12 am
I didn't even get a chance to read the question and it says I got it right. Read ahead buffer acting up????
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
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy