• 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-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...