In this chapter, you'll find recipes showing several of the basic programming constructs available in T-SQL. The chapter is not a complete tutorial to the language. You'll need to read other books for that. A good tutorial, if you need one that begins with first-principles, is Beginning T-SQL 2012 by Scott Shaw and Kathi Kellenberger (Apress, 2012). What you will find in this chapter, though, are fast examples of commonly used constructs such as IF and CASE statements, WHILE loops, and T-SQL cursors.
2-1. Declaring Variables
You want to declare a variable and use it in subsequent T-SQL ...