14,494 questions
Hi @r aper
You can try this.
select ECODE,MEM from TableA as p
unpivot (MEM for val in (MEM1,MEM2,MEM3))as t;
Output:
Best regards,
Percy Tang
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have a table.
create table TableA(
ECODE char(2) NULL,
MEM1 int NULL,
MEM2 int NULL,
MEM3 int NULL);
insert into TableA values
('AA',6234,null,2354),
('BB',null,3568,4564),
('CC',1023,3941,null);
Expect output:
ECODE MEM |
---|
AA 6234
AA 2354
BB 3568
BB 4564
CC 1023
CC 3941
Hi @r aper
You can try this.
select ECODE,MEM from TableA as p
unpivot (MEM for val in (MEM1,MEM2,MEM3))as t;
Output:
Best regards,
Percy Tang
See MS Learn: FROM - Using PIVOT and UNPIVOT