Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Trường hợp. . Sau đó. . . ELSE. . . END Chức năng đầu tiên là khi chúng ta muốn kiểm tra một điều kiện. KHI điều kiện là đúng thì chúng ta có thể làm tiếp tục xử lý, ELSE nếu nó là sai, sau đó chúng ta có thể làm điều gì đó khác. | 380 CHAPTER 11 T-SQL ESSENTIALS UPPER The final example is the reverse of the LOWER function and changes all characters to uppercase. Try It Out UPPER 1. After the declared variable has been set we then use the UPPER function to change the value to uppercase. DECLARE @StringTest char 10 SET @StringTest Robin SELeCt UPPER @StringTest 2. And as you can see from Figure 11-36 Robin becomes ROBIN. 1 Results Message No column name 1 I ROBIN.Ị Figure 11-36. Changing the case of a string to uppercase System Functions System functions are functions that provide extra functionality outside of the boundaries that can be defined as string numeric or date related. Three of these functions will be used extensively throughout our code and therefore you should pay special attention to CASE CAST and ISNULL. CASE WHEN. . .THEN. . .ELSE. . .END The first function is when we wish to test a condition. WHEN that condition is true THEN we can do further processing ELSE if it is false then we can do something else. What happens in the WHEN section and the THEN section can range from another CASE statement to providing a value that sets a column or a variable. The CASE WHEN statement can be used to return a value or if on the right-hand side of an equality statement to set a value. Both of these scenarios are covered in the following examples. Try It Out CASE 1. The example will use a CASE statement to add up customers TransactionDetails.Transactions for the month of August. If the TransactionType is 0 then this is a Debit if it is a 1 then it is a Credit. By using the SUM aggregation we can add up the amounts. Combine this with a GROUP BY where the TransactionDetails. Transactions are split between Credit and Debit and we get two rows in the results set one for debits and one for credits. SET QUOTED_IDENTIFIER OFF SELECT CustomerId CASE WHEN CreditType 0 THEN Debits ELSE Credits END CHAPTER 11 T-SQL ESSENTIALS 381 AS TranType SUM Amount FROM TransactionDetails.Transactions t JOIN .