Procedural Code and CASE Expressions
T-SQL has always included support for procedural programming in the form of control-of-flow statements and cursors. One thing that throws developers from other languages off their guard when migrating to SQL is the peculiar three-valued logic (3VL) we enjoy. I will introduce SQL 3VL, which is different from most other programming languages’ simple two-valued Boolean logic, in this chapter. I will also discuss T-SQL control-of-flow constructs, which allow you to change the normally sequential order of statement execution. Control-of-flow statements allowyou to branch your code logic with statements like IF...ELSE..., perform loops with statements like WHILE, and perform unconditional jumps with the GOTO statement. I will also introduce CASE expressions and CASE-derived functions that return values based on given comparison criteria in an expression. Finally, I will finish the chapter by explaining a topic closely tied to procedural code: SQL cursors.
KeywordsDesign Pattern Procedural Code Statement Block Administrative Task Error Handling
Unable to display preview. Download preview PDF.