add remove split language show hidden hide
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
(No column name)
Microsoft SQL Server 2019 (RTM-CU3) (KB4538853) - 15.0.4023.6 (X64)
 Mar 4 2020 00:59:26
 Copyright (C) 2019 Microsoft Corporation
 Express Edition (64-bit) on Windows Server 2019 Standard 10.0 <X64> (Build 17763: ) (Hypervisor)
type unite Item_ID
First null 1
First null 2
First null 3
Second Unite1 1
Second Unite2 2
Second null 3
type Item_unite_ID1 Item_unite_ID2 Item_unite_ID3
First null null null
Second Unite1 Unite2 null
SELECT [type], 
            MAX(CASE WHEN [Item_ID]='1' THEN unite ELSE NULL END) AS [Item_unite_ID1], 
            MAX(CASE WHEN [Item_ID]='2' THEN unite ELSE NULL END) AS [Item_unite_ID2], 
            MAX(CASE WHEN [Item_ID]='3' THEN unite ELSE NULL END) AS [Item_unite_ID3]  FROM #t group by [type]
Warning: Null value is eliminated by an aggregate or other SET operation.