By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
select @@version;
(No column name) |
---|
Microsoft SQL Server 2022 (RTM) - 16.0.1000.6 (X64) Oct 8 2022 05:58:25 Copyright (C) 2022 Microsoft Corporation Express Edition (64-bit) on Windows Server 2019 Standard 10.0 <X64> (Build 17763: ) (Hypervisor) |
create Table Test (Id int,CoinWeightWarning int, NoteCountWarning int, NoteValueWarning int)
INSERT INTO Test VALUES (165, NULL, NULL, NULL) ,(165, NULL, NULL, NULL) ,(165, NULL, 2000, NULL) ,(165, NULL, NULL, 75000) ,(166, NULL, NULL, NULL) ,(166, NULL, NULL, NULL) ,(166, 10, NULL, NULL) ,(166, NULL, NULL, NULL) ,(166, NULL, 2000, NULL) ,(166, NULL, NULL, 75000)
10 rows affected
select * from test;
Id | CoinWeightWarning | NoteCountWarning | NoteValueWarning |
---|---|---|---|
165 | null | null | null |
165 | null | null | null |
165 | null | 2000 | null |
165 | null | null | 75000 |
166 | null | null | null |
166 | null | null | null |
166 | 10 | null | null |
166 | null | null | null |
166 | null | 2000 | null |
166 | null | null | 75000 |
select id,
max(CoinWeightWarning),
max(NoteCountWarning),
max(NoteValueWarning)
from test
group by id
order by id;
id | (No column name) | (No column name) | (No column name) |
---|---|---|---|
165 | null | 2000 | 75000 |
166 | 10 | 2000 | 75000 |
Warning: Null value is eliminated by an aggregate or other SET operation.