While loop Testing

  • Comments posted to this topic are about the item While loop Testing

    Thanks,
    Shiva N
    Database Consultant

  • Interesting, albeit megalomaniacal question 😀

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

  • Woww .... to many nested While loops 🙂

    Nice question, as its reminded the nested loop depth. Thanks for sharing.

    I wonder what Jeff Moden have to say about this ... :hehe:

  • You have a bug in your code here: SET @strend = @strend + ' SET @intloopCounter=@intloopCounter+1 END '

    and the variable should be @intLoopCounter, case letters depends. With your code on any SQL place it throws errors.

    In Theory, theory and practice are the same...In practice, they are not.
  • Tricky....

    good one...

    Vimal LohaniSQL DBA | MCP (70-461,70-462)==============================The greatest barrier to success is the fear of failure ** Success is a journey not a destination**Think before you print, SAVE TREES, Protect Mother Nature

  • Good question, if you read it carefully you will get the answer right.

    Thanx

    Thanks & Best Regards,
    Hany Helmy
    SQL Server Database Consultant

  • Nice one .....

  • twin.devil (9/10/2014)


    Woww .... to many nested While loops 🙂

    Nice question, as its reminded the nested loop depth. Thanks for sharing.

    I wonder what Jeff Moden have to say about this ... :hehe:

    Yep...

  • Due to an error in the variable name I chose the wrong answer. Interesting to read more about while loop levels, although who would ever need/create a query with that many while loops is baffling me. 😉

  • An interesting question to be sure, but as a general rule, I can't stand loops. On those rare occasions when they're necessary, I'll begrudgingly use one, but I still don't like them.

  • I think the only thing I take away from this question is confirmation that dynamic SQL must be avoided, but if you need it you should at least name your variables with a little more care...


    Just because you're right doesn't mean everybody else is wrong.

  • Personally I detest questions like this. This is testing our ability to be a human compiler and debug code that faced with in the real world I would toss out and rewrite. To me this does not follow the spirit of the QOTD which is to test our knowledge of various aspects of sql server. It doesn't help that the site does a rather lousy job of formatting. While I don't like the question I applaud the effort and hope to see more questions from Shiva in the future.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Thanks Shiva

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • I got a different error than was indicated,

    Msg 102, Level 15, State 1, Line 1289

    Incorrect syntax near 'END'.

    But when I reduced @intMaxLoop from 162 to 161, it worked. So I chose that option, which was wrong. Humph.

  • After seeing the code , I checked the options for answers, when I saw the option, "display shiva 2 times"

    some how I felt this is the answer

    By any chance do you wanted your name to be displayed in the everyone's result set who ever tries this quesion 😛

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

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