假设我有Table1,它看起来像这样:
现在我想在select语句中添加两个新列 并使其在临时表中如下所示:
在新列1中A = 1,在新列2中“球” 在两个新列中B均应留空 新列1中的Z = 17A,新列2中的“足球” 等。
我做了以下事情:
Select [Column1],
'' AS [New Column 1] ,
'' AS [New Column 2],
from Table1
但是,所有要做的就是用空白值创建两个新列:
谢谢您的帮助!
答案 0 :(得分:0)
我解决了!
Select [Column1],
CASE
WHEN ([Column1] = ’A’ ) then ‘1’
WHEN ([Column1] = ’B’ ) then ‘’
WHEN ([Column1] = ’Z’ ) then ‘17A’
WHEN ([Column1] = ’D’ ) then ‘19b’
WHEN ([Column1] = ’F’ ) then ‘oxx’
WHEN ([Column1] = ’O’ ) then ‘’
Else ‘’
END AS [New Column 1],
CASE
WHEN ([Column1] = ’A’ ) then ‘Ball’
WHEN ([Column1] = ’B’ ) then ‘’
WHEN ([Column1] = ’Z’ ) then ‘Soccer’
WHEN ([Column1] = ’D’ ) then ‘Jaja’
WHEN ([Column1] = ’F’ ) then ‘Hello’
WHEN ([Column1] = ’O’ ) then ‘’
ELSE ‘’
END AS [New Column 2]
From Table1