Popular Posts

Saturday, November 7, 2015

SQL Rules of Coding

If you ever google sql for loop, just stop right there.

SQL is by definition a for loop.

A SELECT statement does nothing more than iterate over the rows in the database that satisfy the conditions of the query.

Therefore, if you want a for loop that sets a variable and then does some operation on one row at a time, JUST STOP.  What you really want is a join somehow, and you can get it all done much simpler in terms of code and processing power.  It will be easier to debug and to understand, and you won't have to worry about setting up the attendant variables to process a true for loop.  SQL is a for loop, use it that way!