Recent PostsRecent Posts Popular TopicsPopular Topics
 Home Search Members Calendar Who's On

 Stairway to T-SQL: Beyond The Basics Level 7: Controlling the Flow of Your T-SQL Rate Topic Display Mode Topic Options
Author
 Message
 Posted Monday, May 19, 2014 8:56 AM
 Ten Centuries Group: General Forum Members Last Login: Wednesday, August 17, 2016 10:41 PM Points: 1,043, Visits: 290
 Comments posted to this topic are about the item Stairway to T-SQL: Beyond The Basics Level 7: Controlling the Flow of Your T-SQL Gregory A. Larsen, MVP
Post #1572328
 Posted Wednesday, June 25, 2014 11:06 AM
 SSC Eights! Group: General Forum Members Last Login: Today @ 7:14 PM Points: 861, Visits: 1,851
 What are some real-life examples of using the While statement that don't involve RBAR code?
Post #1586015
 Posted Monday, July 18, 2016 2:51 PM
 Grasshopper Group: General Forum Members Last Login: Monday, July 18, 2016 2:48 PM Points: 15, Visits: 51
 I made a slight change to your code:`DECLARE @I INT = 0;WHILE @I <= 10 BEGIN IF @I%2 = 0 IF TAN(@I) > 0 PRINT 'Value ' + CAST(@I as char(1)) + ' is EVEN and the TANGENT is greater than zero' ELSE PRINT 'Value ' + CAST(@I as char(1)) + ' is EVEN and the TANGENT is less than or equal to zero' ELSE IF TAN(@I) > 0 PRINT 'Value ' + CAST(@I as char(1)) + ' is ODD and the TANGENT is greater than zero' ELSE PRINT 'Value ' + CAST(@I as char(1)) + ' is ODD and the TANGENT is less than or equal to zero' SET @I += 1;END`And the output I got is:Value 0 is EVEN and the TANGENT is less than or equal to zeroValue 1 is ODD and the TANGENT is greater than zeroValue 2 is EVEN and the TANGENT is less than or equal to zeroValue 3 is ODD and the TANGENT is less than or equal to zeroValue 4 is EVEN and the TANGENT is greater than zeroValue 5 is ODD and the TANGENT is less than or equal to zeroValue 6 is EVEN and the TANGENT is less than or equal to zeroValue 7 is ODD and the TANGENT is greater than zeroValue 8 is EVEN and the TANGENT is less than or equal to zeroValue 9 is ODD and the TANGENT is less than or equal to zeroValue * is EVEN and the TANGENT is greater than zeroHow do I handle this? -----------------------------------------------------------------------Known is a DROP, Unknown is an OCEAN.
Post #1802702
 Posted Monday, July 18, 2016 9:29 PM
 SSC-Forever Group: General Forum Members Last Login: Today @ 7:26 PM Points: 41,645, Visits: 39,000
 Marcia J (6/25/2014)What are some real-life examples of using the While statement that don't involve RBAR code?Creating dynamic SQL for backups.The "Bin Fill" and "Load Balancing" problems are classic problems that are difficult to solve without an explicit loop. --Jeff Moden"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column." Helpful Links:How to post code problemsHow to post performance problems
Post #1802747

 Permissions