I am going to continue my articles (tidbits) on controlling the execution flow of statements in a Transaction SQL (T-SQL) program. Every program has to be deterministic on what step to execute next. Otherwise, the computer would be clueless on what to do next. The only exception to this rule is error handling. A runtime error may cause the program to branch to a error handler and exit the program. Today, I want to talk about how to use the BREAK and CONTINUE statements. I hardly ever use these statements…
Tag: database developer
Controlling The Flow – Part 2
I am going to continue my articles (tidbits) on controlling the execution flow of statements in a Transaction SQL (T-SQL) program. Every program has to be deterministic on what step to execute next. Otherwise, the computer would be clueless on what to do next. The only exception to this rule is error handling. A runtime error may cause the program to branch to a error handler and exit the program. Today, I want to talk about waiting a time period before executing a statement. The WAITFOR statement was introduced in…
Controlling The Flow – Part 1
I am going to write a few articles (tidbits) on controlling the execution flow of statements in a Transaction SQL (T-SQL) program. Every program has to be deterministic on what step to execute next. Otherwise, the computer would be clueless on what to do next. The only exception to this rule is error handling. A runtime error may cause the program to branch to a error handler and exit the program. Today, I want to talk about looping for repetition, statement blocks, and conditional execution. Some programming languages support the…
Using Variables
I am going to talk about Transaction SQL variables. Any stored program that does complex business processing will use one of more of variables to craft an algorithm. During my college days, I had to take a couple physics classes. Newton’s second law states that force is equal to mass times acceleration. The comic strip on the left shows how variables in the fourth picture can be used as place holders in a complex equation. This concept is key for crafting very complex programs. The DECLARE keyword is used in…
Logical Functions – IIF()
I am going continuing my short articles or tidbits on Transaction SQL logical functions. These functions were introduced with the SQL Server 2012 release. Both functions have their origins from Visual Basic for Applications (VBA) framework. I think of these function as decision trees. Especially when they are nested to several levels. If you have a kid like I do, you might find the decision tree for dropped food funny. Please see image to left. I will be exploring the IIF function today. The example below uses the RAND function,…
Logical Functions – CHOOSE()
I am going write a couple of tidbits on Transaction SQL logical functions. These functions were introduced with the SQL Server 2012 release. Both functions have their origins from Visual Basic for Applications (VBA) framework. I think of these function as decision trees. Especially when they are nested to several levels. If you have a kid like I do, you might find the decision tree for dropped food funny. Please see image to left. I will be exploring the CHOOSE function today. If you grew up like I did, you…
Operator Precedence
I am going to bring closure to my series of very short articles or tidbits on Transaction SQL Operators. An operator is a symbol specifying an action that is performed on one or more expressions. I will exploring the operator precedence today. In mathematics and computer programming, the order of operations is a set of rules used to clarify which procedures should be performed first in a given mathematical expression. I do not have enough time in this very short article to go over the eight levels that group and…
Unary Operators
I am going to stick to writing my series of very short articles or tidbits on Transaction SQL Operators. An operator is a symbol specifying an action that is performed on one or more expressions. I will exploring the Unary Operators today. In mathematics, a unary operation is an operation with only one operand. Microsoft Transaction SQL has three unary operators: positive, negative, and bitwise not. I have personally used the bitwise operators when dealing with data from car manufacturing devices that use application specific integrated circuits (ASIC). Since the…
String Operators
I am going to press on with my series of very short articles or tidbits on Transaction SQL Operators. An operator is a symbol specifying an action that is performed on one or more expressions. I will exploring the String Operators today. These operators can be broken down into two categories: concatenation and pattern matching. Out of the two operators, pattern matching is the most complex. Transaction SQL has both a simple and compound version of the concatenation operator. This operator takes two strings and combines them into one. Please…
Set Operators
I am going to promote my series of very short articles or tidbits on Transaction SQL Operators. An operator is a symbol specifying an action that is performed on one or more expressions. I will exploring the Set Operators today. A Venn diagram is used to express different operations between sets. The above image represents the four possible operations given two sets, A and B, and three operators. We will get into the operators supported by Microsoft Transaction SQL shortly. To demonstrate these operators, we need a two temporary tables…