

Ten Centuries
Group: General Forum Members
Last Login: Tuesday, January 12, 2016 1:09 PM
Points: 1,042,
Visits: 288





SSC Eights!
Group: General Forum Members
Last Login: Yesterday @ 10:15 AM
Points: 824,
Visits: 1,767


What are some reallife examples of using the While statement that don't involve RBAR code?




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 zero Value 1 is ODD and the TANGENT is greater than zero Value 2 is EVEN and the TANGENT is less than or equal to zero Value 3 is ODD and the TANGENT is less than or equal to zero Value 4 is EVEN and the TANGENT is greater than zero Value 5 is ODD and the TANGENT is less than or equal to zero Value 6 is EVEN and the TANGENT is less than or equal to zero Value 7 is ODD and the TANGENT is greater than zero Value 8 is EVEN and the TANGENT is less than or equal to zero Value 9 is ODD and the TANGENT is less than or equal to zero Value * is EVEN and the TANGENT is greater than zero
How do I handle this?
 Known is a DROP, Unknown is an OCEAN.




SSCForever
Group: General Forum Members
Last Login: Today @ 8:38 AM
Points: 40,989,
Visits: 38,287


Marcia J (6/25/2014) What are some reallife 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 "reebar" and is a "Modenism" for "RowByAgonizingRow".
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 problems How to post performance problems



