Loading...
「ツール」は右上に移動しました。
利用したサーバー: natural-voltaic-titanium
1いいね 57回再生

From Excel to SQL - Conditionals (IIF and CASE)

SQL has an "if" function, just like Excel -- but it has an even better alternative, the CASE statement, for a series of different conditions.

The dbfiddle website can be accessed for free and without an account at:

dbfiddle.uk/

Make sure to use the SQL Server dialect and the AdventureWorks sample database to be able to follow along with these examples!

---------------------------------------------------

To be able to run these examples yourself, you can start with the following SQL code (some of which we'll explain in a later video):

```
SELECT
ID,
AGE
FROM (
VALUES
(1, 10),
(2, 15),
(3, 23),
(4, 18),
(5, NULL)
) AS AGES(ID, AGE)
```

---------------------------------------------------

This is part of the From Excel to SQL playlist, available at:

   • From Excel to SQL  

Check out the previous video at:

   • From Excel to SQL - Operators (+, -, *, /)  

...and the next video at:

   • From Excel to SQL - Date Formatting (FORMAT)  

The written version of this content is also available at:

bilbottom.github.io/sql-learning-materials/from-ex…

---------------------------------------------------

CHAPTERS

00:00 dbfiddle
00:28 Intro
01:39 Immediate IF
04:37 Accounting for missing data
06:32 The CASE statement
11:37 Step-by-step CASE walkthrough
13:36 Multiple conditions in IIF/CASE
15:26 (Options) Lookup tables for organisation
17:10 Wrap Up

コメント