Often, your business logic will comprise complex patterns, and you'll need flexible tools to accommodate those twists and turns. Fortunately, Transact-SQL (T-SQL) supports conditional logic concepts. Within the context of a development language, a conditional logic statement is part of a larger set of statements known as flow-of-control statements. Flow-of-control statements determine which statements to execute, and in what order to execute them. Flow-of-control statements handle both looping and branching duties within a computer language. Within T-SQL, you'll find two conditional statements: IF...ELSE and CASE. If you're like most of us, you'll use IE..ELSE and CASE a lot. In fact, you may find you use IE..ELSE more than just about any other statement. That's because these two statements let your application make decisions. For instance, either statement could determine which discount rate to apply to each customer (when you have varying levels). You might run one or the other to list employees that deserve a commission bonus and how much if commission percentages are based on sales.
展开▼