The Language of SQL- P15

The Language of SQL- P15:Research has shown that, being pressed for time, most readers tend to skip the introduction of any book they happen to read and then proceed immediately to the first real chapter. With that fact firmly in mind, we will only cover relatively unimportant material in the introduction, such as an explanation of what you will and will not learn by reading this book. | This page intentionally left blank CHAPTER 6 Column-Based Logic Keywords Introduced CASE WHEN THEN ELSE END The main topic of this chapter is something called the CASE expression. As indicated by the title of this chapter CASE expressions are a form of column-based logic. That term is meant to indicate that these expressions apply logic to columns rather than rows. CASE expressions are also sometimes referred to as conditional logic. Basically CASE expressions allow you to alter the output you present to a user based on a logical condition as it applies to an evaluation of specific columns or data elements. As a beginning SQL developer you should know that the CASE expression is a relatively advanced topic. You can get by without ever using CASE expressions and still write some useful queries. But your knowledge of this topic is the type of thing that can really set you apart. In fact after you ve gone through the entire book this is one of the topics you may want to review again to get you thinking about some of the interesting things that can be accomplished with this technique. IF-THEN-ELSE Logic Let s turn to some honest-to-goodness logic next. Up until now you ve learned how to select columns from a single table apply some calculations and functions and add a sort. However you have not yet done anything all that logical. 57 58 Chapter 6 Column-Based Logic The CASE expression in SQL enables you to apply a traditional IF-THEN-ELSE type of logic to a single expression in a SELECT statement. The term IF-THEN-ELSE refers to a commonly used logical construct employed by procedural programming languages. In general terms this type of logic looks like IF some condition is true THEN do this ELSE do that A CASE expression is a construct that can appear in a number of places in a SELECT statement. In this chapter we re going to focus on CASE expressions that appear within the columnlist immediately following the SELECT keyword. A SELECT statement that includes both .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.