select in case statement code example

Example 1: sql CASE

/*CASE statements are used to create different outputs and is 
  used by SQL as a way to handle if-then logic.*/
  
  SELECT column_name,
    CASE 
      WHEN condition THEN 'Result_1'
      WHEN condition THEN 'Result_2'
      ELSE 'Result_3'
    END
  FROM table_name;

Example 2: how to write if case in select query in select statement

SELECT player_name,
       CASE WHEN year = 'FR' AND position = 'WR' THEN 'frosh_wr'
            ELSE NULL END AS sample_case_statement
  FROM benn.college_football_players

Tags:

Vb Example