Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Predict output


Predict output

Author
Message
vk-kirov
vk-kirov
Hall of Fame
Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)

Group: General Forum Members
Points: 3494 Visits: 4408
pg53 (1/21/2010)
Apart from that, what's going on with the transaction? ... that rollback in the middle - can you do that?

You can roll back a transaction in the middle, in the end, or even in the beginning of a batch – it's no problem with that :-)
Saurabh Dwivedy
Saurabh Dwivedy
SSC-Addicted
SSC-Addicted (488 reputation)SSC-Addicted (488 reputation)SSC-Addicted (488 reputation)SSC-Addicted (488 reputation)SSC-Addicted (488 reputation)SSC-Addicted (488 reputation)SSC-Addicted (488 reputation)SSC-Addicted (488 reputation)

Group: General Forum Members
Points: 488 Visits: 340
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!
prahaladd
prahaladd
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
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.
Kelsey Thornton
Kelsey Thornton
Mr or Mrs. 500
Mr or Mrs. 500 (559 reputation)Mr or Mrs. 500 (559 reputation)Mr or Mrs. 500 (559 reputation)Mr or Mrs. 500 (559 reputation)Mr or Mrs. 500 (559 reputation)Mr or Mrs. 500 (559 reputation)Mr or Mrs. 500 (559 reputation)Mr or Mrs. 500 (559 reputation)

Group: General Forum Members
Points: 559 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
ChiragNS
ChiragNS
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2409 Visits: 1865
Learnt some thing . But does'nt Set ansi_warning have an impact.

"Keep Trying"
HardCoder
HardCoder
SSC Veteran
SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)

Group: General Forum Members
Points: 215 Visits: 103
Output answer should be
1
2
4
5


why this option was not there??

Mohammad Irfan
http://matespoint.blogspot.com
http://www.irfit.com
wim.buyens
wim.buyens
SSC Veteran
SSC Veteran (277 reputation)SSC Veteran (277 reputation)SSC Veteran (277 reputation)SSC Veteran (277 reputation)SSC Veteran (277 reputation)SSC Veteran (277 reputation)SSC Veteran (277 reputation)SSC Veteran (277 reputation)

Group: General Forum Members
Points: 277 Visits: 188
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.
ColdCoffee
ColdCoffee
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2317 Visits: 5545
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...
HardCoder
HardCoder
SSC Veteran
SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)

Group: General Forum Members
Points: 215 Visits: 103
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
Shahd Ansari
Shahd Ansari
Valued Member
Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)

Group: General Forum Members
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.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search