I am trying to create new columns labelled as the values in "stno" with each containing its respective value in "qyhnd" and keeping it in order by "pano20." So if pano20 is 6Y9807, and stno is 02, and qyhnd is 6, then my new column labelled 02 should have the value of 6 for pano20 6Y9807. The examples of what I currently have and what I am trying to achieve are below. Thanks
What I have now:
PANO20 | QYHND | STNO |
---|---|---|
6Y9807 | 6 | 02 |
6N3191 | 8 | 01 |
1476605 | 15 | 02 |
1672190 | 6 | 01 |
2641440 | 2 | 00 |
I am trying to get:
PANO20 | QYHND | STNO | 00 | 01 | 02 |
---|---|---|---|---|---|
6Y9807 | 6 | 02 | 6 | ||
6N3191 | 8 | 01 | 8 | ||
1476605 | 15 | 02 | 15 | ||
1672190 | 6 | 01 | 6 | ||
2641440 | 2 | 00 | 2 |
This is my attempt:
select ps.PANO20, ps.SOS1, ps.QYHND, ps.QYOR, ps.MIN, ps.MAX, ps.STNO, ps.SKNSKI, ms.SOS1, ms.UNCS, SUM (DMMO01+ DMMO02+ DMMO03+ DMMO04+ DMMO05+ DMMO06+ DMMO07+ DMMO08+ DMMO09+ DMMO10+ DMMO11+ DMMO12) as [Demand12]
from LIBH07.dbo.PCPPIST0 ps
inner join LIBCOM500.dbo.PCPPRMS0 ms
on ps.PANO20 = ms.PANO20
where ps.STNO IN ('00','01','02','03') and ps.SOS1 = '000' and ms.SOS1 = '000'
group by ps.SOS1, ps.PANO20, qyhnd, qyor, MIN, MAX, stno, sknski, ms.sos1, ms.UNCS
order by PANO20 desc
create table OnHandStore
as select PANO20,
SUM(case when stno = '00' then qyhnd end) as Henderson,
SUM(case when stno = '01' then qyhnd end) as Reno,
SUM(case when stno = '02' then qyhnd end) as Elko,
SUM(case when stno = '03' then qyhnd end) as Winnemucca,
from pcppist0 as t1
group by PANO20;