While loop

  • sreenivas.kumarreddy

    SSC Enthusiast

    Points: 143

    Comments posted to this topic are about the item While loop

  • Ron McCullough

    SSC Guru

    Points: 63877

    Nice question as long as you read it carefully

    Thanks

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • A.jafari

    SSC Rookie

    Points: 41

    Thanks For Good Question ,

    Please illustrate diffrent between "Begin Catch" And "Try Except"

    :-):hehe:

    Thanks

  • Lokesh Vij

    SSChampion

    Points: 10836

    Ah....an easy one. Thanks Sreenivas 🙂

    ~ Lokesh Vij


    Guidelines for quicker answers on T-SQL question[/url]
    Guidelines for answers on Performance questions

    Link to my Blog Post --> www.SQLPathy.com[/url]

    Follow me @Twitter

  • ziangij

    SSCertifiable

    Points: 6954

    Thanks for the question. It seems that the catch block is just for confusing 🙂 coz. the select query in the catch block doesn't execute

  • demonfox

    SSCertifiable

    Points: 6289

    yes, nice question; try and catch doesn't hold anything.. even if you put the above code in a transaction it would still give 11.

    well, instead of 10/0.00001 try using 10/0 , guess what the answer could be 😀

    Thanks.

    ~ demonfox
    ___________________________________________________________________
    Wondering what I would do next , when I am done with this one :ermm:

  • Lokesh Vij

    SSChampion

    Points: 10836

    demonfox (10/9/2012)


    well, instead of 10/0.00001 try using 10/0 , guess what the answer could be 😀

    Initially I thought this division is the key to answer this question; as "0.00001" is nearly equal to zero, the statement 10/0.00001 will introduce "divide by zero" error and hence catch block will come into picture :hehe:

    All these wacky thoughts went away and I marked the correct answer. Thanks to the "Espresso Coffee" which did the magic 😀

    ~ Lokesh Vij


    Guidelines for quicker answers on T-SQL question[/url]
    Guidelines for answers on Performance questions

    Link to my Blog Post --> www.SQLPathy.com[/url]

    Follow me @Twitter

  • Koen Verbeeck

    SSC Guru

    Points: 258938

    Thanks for the question.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • kapil_kk

    SSC-Insane

    Points: 21316

    Hi,

    I am new in field of DBA...

    I just want to know that can we assign value to a variable through SELECT statement also as done in the

    question

    Select @STR=1,

    whts the difference between -

    Set @STR=1

    select @STR=1

    in this quesion?

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • This was removed by the editor as SPAM

  • kapil_kk

    SSC-Insane

    Points: 21316

    thanks Stewart for the explanation...

    Learned something new today

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • demonfox

    SSCertifiable

    Points: 6289

    Lokesh Vij (10/9/2012)


    demonfox (10/9/2012)


    well, instead of 10/0.00001 try using 10/0 , guess what the answer could be 😀

    Initially I thought this division is the key to answer this question; as "0.00001" is nearly equal to zero, the statement 10/0.00001 will introduce "divide by zero" error and hence catch block will come into picture :hehe:

    All these wacky thoughts went away and I marked the correct answer. Thanks to the "Espresso Coffee" which did the magic 😀

    well yes, catch block would come into the picture ; and the answer would be 4 ; the loop continues till codition breaks that.

    Declare @ctr int

    select @ctr = 1

    while @ctr <= 10

    begin

    select '1'

    if @ctr = 4

    select 10/0

    select @ctr = @ctr+1

    end

    end try

    begin catch

    select @ctr

    end catch

    select @ctr 'Counter'

    ~ demonfox
    ___________________________________________________________________
    Wondering what I would do next , when I am done with this one :ermm:

  • derek.colley

    SSCrazy Eights

    Points: 8040

    Decent question with lots of red herrings, many thanks 🙂

    ---

    Note to developers:
    CAST(SUBSTRING(CAST(FLOOR(NULLIF(ISNULL(COALESCE(1,NULL),NULL),NULL)) AS CHAR(1)),1,1) AS INT) == 1
    So why complicate your code AND MAKE MY JOB HARDER??!:crazy:

    Want to get the best help? Click here https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help (Jeff Moden)
    My blog: http://uksqldba.blogspot.com
    Visit http://www.DerekColley.co.uk to find out more about me.

  • Hugo Kornelis

    SSC Guru

    Points: 64645

    A.jafari (10/9/2012)


    Please illustrate diffrent between "Begin Catch" And "Try Except"

    You can read about TRY ... CATCH here: http://msdn.microsoft.com/en-us/library/ms175976.aspx

    In T-SQL, "Try Except" is invalid syntax. I have no idea what language this comes from and what it does, but it sounds as just a slightly different way to solve the same problem (error handling).


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • Andre Guerreiro

    SSCertifiable

    Points: 7319

    Thank you for the question.

    I was almost choosing the error answer because of the 10/0.00001 but then I drank some coffee and thought about it for one more second. 😀

    Best regards,

    Andre Guerreiro Neto

    Database Analyst
    http://www.softplan.com.br
    MCITPx1/MCTSx2/MCSE/MCSA

Viewing 15 posts - 1 through 15 (of 39 total)

You must be logged in to reply to this topic. Login to reply