January 28, 2010 at 8:36 am
the select only returns 1 2 4 5 .
this is an exception is not returned by the select, so actually i don't feel this is a good question.
I knew which one to choose but it's not 100% correct.
January 29, 2010 at 1:23 am
Mohammad Irfan-488206 (1/28/2010)
Output answer should be1
2
4
5
why this option was not there??
I guess u did not look up at the "Messages" tab in the Results Pane..
For those intending to get the exact answer given in the choices, run this code
set nocount on
drop table #temp
declare @i int, @j-2 int
set @i = 1
create table #temp (id int)
while (@i<=5)
begin
begin try
begin transaction
if (@i = 3)
set @j-2 = @i/0
insert into #temp values (@i)
print cast (@i as varchar(5))
commit transaction
end try
begin catch
rollback transaction
print 'this is an exception';
end catch
set @i = @i + 1
end
Excellent question to learn exception-catching in a loop...
January 29, 2010 at 1:38 am
COldCoffee (1/29/2010)
Mohammad Irfan-488206 (1/28/2010)
Output answer should be1
2
4
5
why this option was not there??
I guess u did not look up at the "Messages" tab in the Results Pane..
For those intending to get the exact answer given in the choices, run this code
set nocount on
drop table #temp
declare @i int, @j-2 int
set @i = 1
create table #temp (id int)
while (@i<=5)
begin
begin try
begin transaction
if (@i = 3)
set @j-2 = @i/0
insert into #temp values (@i)
print cast (@i as varchar(5))
commit transaction
end try
begin catch
rollback transaction
print 'this is an exception';
end catch
set @i = @i + 1
end
Excellent question to learn exception-catching in a loop...
Ok thanks, but the question was about what will be the output, not message, else you may get many messages like 1 row affected...
Mohammad Irfan
http://matespoint.blogspot.com
http://www.irfit.com
January 29, 2010 at 9:43 am
Hi, This question havn't right answer.
at condition when i = 3 then exception will be occur , in that case transaction not commit and rollback in catch block, so that record will not inter in the #temp..
That why Select * from # Temp, will give the following answer...
1
2
4
5
Please Check you question and answer before post.
January 29, 2010 at 9:56 am
The answer is arguably correct since an exception occurs and is handled in the code. The order of what appears, and where, depends on your client.
The question has been edited to separate out "results" and "messages"
February 2, 2010 at 1:18 am
I really disagrree with the answer 1245.
the actual resul it is 12345.
if @i = 3 then we are setting J = @i/0;
so there no use of this statement finally we are storing the i value in to the temparory table.
February 3, 2010 at 6:44 am
srinivas.thadem (2/2/2010)
I really disagrree with the answer 1245.the actual resul it is 12345.
if @i = 3 then we are setting J = @i/0;
so there no use of this statement finally we are storing the i value in to the temparory table.
You can't divide by 0.... unless your name is Chuck Norris.
March 15, 2010 at 10:36 pm
I like to think of the right answer as being the one "closest" to being right, which was the right answer which I chose despite knowing that the output did not look exactly correct but could not possibly be the other choices in any order.
Another good exercise for the kiddies in class! Keep those QOTD's coming!
Peter Trast
Microsoft Certified ...(insert many literal strings here)
Microsoft Design Architect with Alexander Open Systems
March 30, 2010 at 10:32 am
Liked the use of TRY...CATCH (though checking XACT_STATE would be cool).
Disliked the loop.
On balance: not bad.
November 24, 2011 at 2:07 pm
A poorly worded trick question.
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Viewing 10 posts - 46 through 54 (of 54 total)
You must be logged in to reply to this topic. Login to reply