CASE: return a specified value based on a set of business logic : Case « Select Query « SQL Server / T-SQL






CASE: return a specified value based on a set of business logic


11>
12> -- CASE: return a specified value based on a set of business logic
13>
14> DECLARE @Status Int
15> SET @Status = 1
16>
17> SELECT CASE @Status
18>   WHEN 1 THEN 'Active'
19>   WHEN 2 THEN 'Inactive'
20>   WHEN 3 THEN 'Pending'
21> END
22>
23> GO

--------
Active

(1 rows affected)
1>
           
       








Related examples in the same category

1.Select case statement
2.Case when and else
3.Use CASE in the UPDATE statement
4.'Case when' statement in a procedure
5.Case When with else
6.Case when NULL
7.Case when with Mod and ABS()
8.A simple CASE takes an expression that equates to a Boolean result