在select语句中插入具有唯一值的2个新列

时间:2022-01-16 22:40:29

Let's say I have Table1 and it looks like this :

假设我有Table1,它看起来像这样:

在select语句中插入具有唯一值的2个新列

Now I want to add two new columns in a select statement and make it look like this in a temporary table :

现在我想在select语句中添加两个新列,并使它在临时表中看起来像这样:

在select语句中插入具有唯一值的2个新列

A= 1 in New Column 1 and "Ball" in New Column 2 B should be left blank in both new columns Z = 17A in New Column 1 and "Soccer" in New Column 2 and etc.

新列1中的A = 1和新列2 B中的“球”应在新列1中的新列Z = 17A和新列2中的“足球”等处留空。

I did the following :

我做了以下事情:

    Select [Column1],
    '' AS [New Column 1] ,
    '' AS [New Column 2],

    from Table1

However, all this does is create the two new columns with blank values:

但是,所有这一切都是使用空值创建两个新列:

在select语句中插入具有唯一值的2个新列

Thank you for your help in advance!

提前谢谢你的帮助!

1 个解决方案

#1


0  

I solved it!

我解决了!

    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

#1


0  

I solved it!

我解决了!

    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