mssql에서 case when를 처리하는 문법
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
https://docs.microsoft.com/ko-kr/sql/t-sql/language-elements/case-transact-sql?view=sql-server-ver15 | |
*/ | |
--Simple CASE expression | |
SELECT ListName, | |
CASE ListId | |
WHEN 1 THEN 'ListId_1' | |
WHEN 2 THEN 'ListId_2' | |
WHEN 3 THEN 'ListId_3' | |
WHEN 3 THEN 'ListId_4' | |
ELSE 'ListId_else' | |
END AS 'ListId' | |
FROM dbo.Lists WITH(NOLOCK) | |
--Searched CASE expression | |
SELECT ListName, | |
CASE | |
WHEN ListId IN (1,2) THEN 'ListId_1_2' | |
WHEN ListId IN (3,4) THEN 'ListId_3_4' | |
ELSE 'ListId_Else' | |
END AS 'ListId' | |
FROM dbo.Lists WITH(NOLOCK) |
'IT' 카테고리의 다른 글
[vue] vue 기초 data methods mount (0) | 2020.12.03 |
---|---|
[python] 중복 제거 set, list (0) | 2020.11.21 |
[inteliJ] lombok 설정 세팅 annotation (0) | 2020.11.19 |
[MSSQL] REPLACE 문자 치환 (0) | 2020.11.18 |
[python] 여러개의 랜카드 ip 추출 (0) | 2020.11.16 |