Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««23456»»

Predict output Expand / Collapse
Author
Message
Posted Thursday, January 21, 2010 9:41 AM


SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Sunday, November 2, 2014 9:13 AM
Points: 488, Visits: 338
I too, like most others, initially felt inclined to believe none of the answers was PERFECTLY CORRECT because the text - in the middle of the answer set - was a bit misleading - mainly because everyone expected the OUTPUT to come from the select * from #temp, which could not "emit" the output displayed in the answer choices.

However, I chose the right answer because there didn't seem to be any other answer coming close. The "right answer" had all the ingredients though not exactly in the 'proper way'.

I see both sides of the argument - one asserting that "There is no correct answer" and the other inviting us to focus on the "larger picture".

My only submission is for us to be a little more considerate for the poster. Someone has spent some time and effort creating the question. Creating is not an easy business and I quite liked the frankness displayed by another poster on the forum who openly accepted he wasn't quite wired for doing such a thing. Let's be a little considerate, folks. Let's also keep in mind that even those posting the questions may not be experts at creating questions. I don't think we have folks dedicated here to proof-read questions thoroughly before the questions are printed. If we are so irked by "inappropriate/incorrect" question why don't we form a volunteer group (on a revolving basis maybe) who would do the needful.

Somebody brought GRE type questions into the picture which was again very surprising. This is a forum for learning and sharing. Let's give kudos and help make this forum a great learning experience for everyone.

If anything - pure criticism without being properly backed by a plan of action to fix the source of criticism is a sheer waste of time IMHO.

Regards
Saurabh


Saurabh Dwivedy
___________________________________________________________

My Blog: http://tinyurl.com/dwivedys

For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537

Be Happy!
Post #851381
Posted Thursday, January 21, 2010 10:39 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, July 18, 2010 7:16 AM
Points: 4, Visits: 4
Hi,

The CATCH clause in SQL server does exactly what a catch(Exception ex) in C# does. Also the ROLLBACK is perfectly valid; imagine what would happen if there was no TRY.. CATCH within the given sample code. In that case after opening a transaction, there would be a divide by zero error and this is analogous to an error in the transaction which would eventually result in it's roll back.
Post #851427
Posted Friday, January 22, 2010 1:41 AM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Thursday, March 27, 2014 8:16 AM
Points: 534, Visits: 282
Saurabh Dwivedy (1/21/2010)

<snip>
My only submission is for us to be a little more considerate for the poster. Someone has spent some time and effort creating the question. Creating is not an easy business and I quite liked the frankness displayed by another poster on the forum who openly accepted he wasn't quite wired for doing such a thing. Let's be a little considerate, folks. Let's also keep in mind that even those posting the questions may not be experts at creating questions.
<snip>
Regards
Saurabh


Hear hear!


Kelsey Thornton
MBCS CITP
Post #851805
Posted Friday, January 22, 2010 5:26 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, September 23, 2014 8:08 AM
Points: 2,365, Visits: 1,846
Learnt some thing . But does'nt Set ansi_warning have an impact.

"Keep Trying"
Post #851929
Posted Thursday, January 28, 2010 12:03 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, September 26, 2014 12:42 AM
Points: 215, Visits: 99
Output answer should be
1
2
4
5


why this option was not there??


Mohammad Irfan
http://matespoint.blogspot.com
http://www.irfit.com
Post #854950
Posted Thursday, January 28, 2010 8:36 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Tuesday, October 28, 2014 2:23 AM
Points: 237, Visits: 147
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.
Post #855334
Posted Friday, January 29, 2010 1:23 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Thursday, December 11, 2014 5:03 PM
Points: 2,262, Visits: 5,427
Mohammad Irfan-488206 (1/28/2010)
Output answer should be
1
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 int
set @i = 1
create table #temp (id int)
while (@i<=5)
begin
begin try
begin transaction
if (@i = 3)
set @j = @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...
Post #855847
Posted Friday, January 29, 2010 1:38 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, September 26, 2014 12:42 AM
Points: 215, Visits: 99
COldCoffee (1/29/2010)
Mohammad Irfan-488206 (1/28/2010)
Output answer should be
1
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 int
set @i = 1
create table #temp (id int)
while (@i<=5)
begin
begin try
begin transaction
if (@i = 3)
set @j = @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
Post #855858
Posted Friday, January 29, 2010 9:43 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, February 16, 2012 12:57 AM
Points: 63, Visits: 29
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.
Post #856206
Posted Friday, January 29, 2010 9:56 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Yesterday @ 3:11 PM
Points: 31,368, Visits: 15,837
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"







Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #856217
« Prev Topic | Next Topic »

Add to briefcase «««23456»»

Permissions Expand / Collapse