This question already has answers here:
SQL Server: Examples of PIVOTing String data
(7 answers)
Closed 8 years ago.
I have a table like this:
HospitalName--- DRG--DrgCount
K1 F67A 1
K1 F68A 1
K1 F69A 1
K1 F60A 1
K1 F61A 1
K2 F61A 1
I want to show this in SQL Server like this:
HospitalName F67A F68A F69A F60A F61A
K1 1 1 1 1 1
K2 0 0 0 0 1
I tried the code below :
SELECT TOP 1000 HospitalCode,Durum,[A01Z],[A03Z],[A05Z],[Z99A],[Z98A],[Z97A],[Z96A],[A06Z],[A07Z],[A08A],[A08B],[A09A],[A09B],[A40Z],[A41A],[A41B],[B01Z],[B02A],[B02B],[B02C],[B03A],[B03B],[B04A],[B04B],[B05Z],[B06A],[B06B],[B07A],[B07B],[B40Z],[B41Z],[B60A],[B60B],[B61A],[B61B],[B62Z],[B63Z],[B64A],[B64B],[B65Z],[B66A],[B66B],[B67A],[B67B],[B67C],[B68A],[B68B],[B69A],[B69B],[B70A],[B70B],[B70C],[B70D],[B71A],[B71B],[B72A],[B72B],[B73Z],[B74Z],[B75Z],[B76A],[B76B],[B77Z],[B78A],[B78B],[B79Z],[B80Z],[B81A],[B81B],[C01Z],[C02Z],[C03Z],[C04Z],[C05Z],[C10Z],[C11Z],[C12Z],[C13Z],[C14Z],[C15A],[C15B],[C16A],[C16B],[C60A],[C60B],[C61Z],[C62Z],[C63A],[C63B],[D01Z],[D02A],[D02B],[D02C],[D03Z],[D04A],[D04B],[D05Z],[D06Z],[D09Z],[D10Z],[D11Z],[D12Z],[D13Z],[D14Z],[D40Z],[D60A],[D60B],[D61Z],[D62Z],[D63A],[D63B],[D64Z],[D65Z],[D66A],[D66B],[D67A],[D67B],[E01A],[E01B],[E02A],[E02B],[E02C],[E40Z],[E41Z],[E60A],[E60B],[E61A],[E61B],[E62A],[E62B],[E62C],[E63Z],[E64Z],[E65A],[E65B],[E66A],[E66B],[E66C],[E67A],[E67B],[E68Z],[E69A],[E69B],[E69C],[E70A],[E70B],[E71A],[E71B],[E71C],[E72Z],[E73A],[E73B],[E73C],[E74A],[E74B],[E74C],[E75A],[E75B],[E75C],[F01A],[F01B],[F02Z],[F03Z],[F04A],[F04B],[F05A],[F05B],[F06A],[F06B],[F07A],[F07B],[F08A],[F08B],[F09A],[F09B],[F10Z],[F11A],[F11B],[F12Z],[F13Z],[F14A],[F14B],[F14C],[F15Z],[F16Z],[F17Z],[F18Z],[F19Z],[F20Z],[F21A],[F21B],[F40Z],[F41A],[F41B],[F42A],[F42B],[F60A],[F60B],[F60C],[F61Z],[F62A],[F62B],[F63A],[F63B],[F64Z],[F65A],[F65B],[F66A],[F66B],[F67A],[F67B],[F68Z],[F69A],[F69B],[F70A],[F70B],[F71A],[F71B],[F72A],[F72B],[F73A],[F73B],[F74Z],[F75A],[F75B],[F75C],[G01A],[G01B],[G02A],[G02B],[G03A],[G03B],[G03C],[G04A],[G04B],[G04C],[G05A],[G05B],[G06Z],[G07A],[G07B],[G08A],[G08B],[G09Z],[G10Z],[G11A],[G11B],[G12A],[G12B],[G42A],[G42B],[G43Z],[G44A],[G44B],[G44C],[G45A],[G45B],[G46A],[G46B],[G46C],[G60A],[G60B],[G61A],[G61B],[G62Z],[G63Z],[G64Z],[G65A],[G65B],[G66A],[G66B],[G67A],[G67B],[G68A],[G68B],[G69Z],[G70A],[G70B],[H01A],[H01B],[H02A],[H02B],[H02C],[H05A],[H05B],[H06Z],[H07A],[H07B],[H08A],[H08B],[H40Z],[H41A],[H41B],[H42A],[H42B],[H42C],[H60A],[H60B],[H60C],[H61A],[H61B],[H62A],[H62B],[H63A],[H63B],[H64A],[H64B],[I01Z],[I02A],[I02B],[I03A],[I03B],[I03C],[I04Z],[I05Z],[I06Z],[I07Z],[I08A],[I08B],[I09A],[I09B],[I10A],[I10B],[I11Z],[I12A],[I12B],[I12C],[I13A],[I13B],[I13C],[I14Z],[I15Z],[I16Z],[I17Z],[I18Z],[I19Z],[I20Z],[I21Z],[I23Z],[I24Z],[I25Z],[I27A],[I27B],[I28A],[I28B],[I29Z],[I30Z],[I60Z],[I61Z],[I63Z],[I64A],[I64B],[I65A],[I65B],[I66A],[I66B],[I67A],[I67B],[I68A],[I68B],[I68C],[I69A],[I69B],[I69C],[I70Z],[I71A],[I71B],[I71C],[I72A],[I72B],[I73A],[I73B],[I73C],[I74A],[I74B],[I74C],[I75A],[I75B],[I75C],[I76A],[I76B],[I76C],[I77A],[I77B],[I78A],[I78B],[J01Z],[J06A],[J06B],[J07A],[J07B],[J08A],[J08B],[J09Z],[J10Z],[J11Z],[J12A],[J12B],[J12C],[J13A],[J13B],[J14Z],[J60A],[J60B],[J62A],[J62B],[J63Z],[J64A],[J64B],[J65A],[J65B],[J67A],[J67B],[J68A],[J68B],[K01Z],[K02Z],[K03Z],[K04Z],[K05Z],[K06Z],[K07Z],[K08Z],[K09Z],[K40Z],[K60A],[K60B],[K61Z],[K62A],[K62B],[K62C],[K63Z],[K64A],[K64B],[L02A],[L02B],[L03A],[L03B],[L04A],[L04B],[L04C],[L05A],[L05B],[L06A],[L06B],[L07A],[L07B],[L08A],[L08B],[L09A],[L09B],[L09C],[L40Z],[L41Z],[L42Z],[L60A],[L60B],[L60C],[L61Z],[L62A],[L62B],[L63A],[L63B],[L63C],[L64Z],[L65A],[L65B],[L66Z],[L67A],[L67B],[L67C],[M01Z],[M02A],[M02B],[M03A],[M03B],[M04A],[M04B],[M05Z],[M06A],[M06B],[M40Z],[M60A],[M60B],[M61A],[M61B],[M62A],[M62B],[M63Z],[M64Z],[N01Z],[N02A],[N02B],[N03A],[N03B],[N04Z],[N05A],[N05B],[N06Z],[N07Z],[N08Z],[N09Z],[N10Z],[N11A],[N11B],[N60A],[N60B],[N61Z],[N62A],[N62B],[O01A],[O01B],[O01C],[O02A],[O02B],[O03Z],[O04Z],[O05Z],[O60A],[O60B],[O60C],[O61Z],[O63Z],[O64A],[O64B],[O66A],[O66B],[P01Z],[P02Z],[P03Z],[P04Z],[P05Z],[P06A],[P06B],[P60A],[P60B],[P61Z],[P62Z],[P63Z],[P64Z],[P65A],[P65B],[P65C],[P65D],[P66A],[P66B],[P66C],[P66D],[P67A],[P67B],[P67C],[P67D],[Q01Z],[Q02A],[Q02B],[Q60A],[Q60B],[Q60C],[Q61A],[Q61B],[Q61C],[Q62Z],[R01A],[R01B],[R02A],[R02B],[R03A],[R03B],[R04A],[R04B],[R60A],[R60B],[R60C],[R61A],[R61B],[R61C],[R62A],[R62B],[R63Z],[R64Z],[S60Z],[S65A],[S65B],[S65C],[T01A],[T01B],[T01C],[T60A],[T60B],[T61A],[T61B],[T62A],[T62B],[T63A],[T63B],[T64A],[T64B],[U40Z],[U60Z],[U61A],[U61B],[U62A],[U62B],[U63A],[U63B],[U64Z],[U65Z],[U66Z],[U67Z],[U68Z],[V60A],[V60B],[V61Z],[V62A],[V62B],[V63A],[V63B],[V64Z],[W01Z],[W02Z],[W03Z],[W04Z],[W60Z],[W61Z],[X02Z],[X04A],[X04B],[X05Z],[X06A],[X06B],[X07A],[X07B],[X60A],[X60B],[X60C],[X61Z],[X62A],[X62B],[X63A],[X63B],[X64A],[X64B],[Y01Z],[Y02A],[Y02B],[Y03Z],[Y60Z],[Y61Z],[Y62A],[Y62B],[Z01A],[Z01B],[Z40Z],[Z60A],[Z60B],[Z60C],[Z61Z],[Z62Z],[Z63A],[Z63B],[Z64A],[Z64B],[Z65Z],[901Z],[902Z],[903Z],[960Z],[961Z],[963Z]
FROM
(SELECT * FROM TIGPatient) p
PIVOT
(
COUNT (DRG)
FOR DRG IN
( [A01Z],[A03Z],[A05Z],[Z99A],[Z98A],[Z97A],[Z96A],[A06Z],[A07Z],[A08A],[A08B],[A09A],[A09B],[A40Z],[A41A],[A41B],[B01Z],[B02A],[B02B],[B02C],[B03A],[B03B],[B04A],[B04B],[B05Z],[B06A],[B06B],[B07A],[B07B],[B40Z],[B41Z],[B60A],[B60B],[B61A],[B61B],[B62Z],[B63Z],[B64A],[B64B],[B65Z],[B66A],[B66B],[B67A],[B67B],[B67C],[B68A],[B68B],[B69A],[B69B],[B70A],[B70B],[B70C],[B70D],[B71A],[B71B],[B72A],[B72B],[B73Z],[B74Z],[B75Z],[B76A],[B76B],[B77Z],[B78A],[B78B],[B79Z],[B80Z],[B81A],[B81B],[C01Z],[C02Z],[C03Z],[C04Z],[C05Z],[C10Z],[C11Z],[C12Z],[C13Z],[C14Z],[C15A],[C15B],[C16A],[C16B],[C60A],[C60B],[C61Z],[C62Z],[C63A],[C63B],[D01Z],[D02A],[D02B],[D02C],[D03Z],[D04A],[D04B],[D05Z],[D06Z],[D09Z],[D10Z],[D11Z],[D12Z],[D13Z],[D14Z],[D40Z],[D60A],[D60B],[D61Z],[D62Z],[D63A],[D63B],[D64Z],[D65Z],[D66A],[D66B],[D67A],[D67B],[E01A],[E01B],[E02A],[E02B],[E02C],[E40Z],[E41Z],[E60A],[E60B],[E61A],[E61B],[E62A],[E62B],[E62C],[E63Z],[E64Z],[E65A],[E65B],[E66A],[E66B],[E66C],[E67A],[E67B],[E68Z],[E69A],[E69B],[E69C],[E70A],[E70B],[E71A],[E71B],[E71C],[E72Z],[E73A],[E73B],[E73C],[E74A],[E74B],[E74C],[E75A],[E75B],[E75C],[F01A],[F01B],[F02Z],[F03Z],[F04A],[F04B],[F05A],[F05B],[F06A],[F06B],[F07A],[F07B],[F08A],[F08B],[F09A],[F09B],[F10Z],[F11A],[F11B],[F12Z],[F13Z],[F14A],[F14B],[F14C],[F15Z],[F16Z],[F17Z],[F18Z],[F19Z],[F20Z],[F21A],[F21B],[F40Z],[F41A],[F41B],[F42A],[F42B],[F60A],[F60B],[F60C],[F61Z],[F62A],[F62B],[F63A],[F63B],[F64Z],[F65A],[F65B],[F66A],[F66B],[F67A],[F67B],[F68Z],[F69A],[F69B],[F70A],[F70B],[F71A],[F71B],[F72A],[F72B],[F73A],[F73B],[F74Z],[F75A],[F75B],[F75C],[G01A],[G01B],[G02A],[G02B],[G03A],[G03B],[G03C],[G04A],[G04B],[G04C],[G05A],[G05B],[G06Z],[G07A],[G07B],[G08A],[G08B],[G09Z],[G10Z],[G11A],[G11B],[G12A],[G12B],[G42A],[G42B],[G43Z],[G44A],[G44B],[G44C],[G45A],[G45B],[G46A],[G46B],[G46C],[G60A],[G60B],[G61A],[G61B],[G62Z],[G63Z],[G64Z],[G65A],[G65B],[G66A],[G66B],[G67A],[G67B],[G68A],[G68B],[G69Z],[G70A],[G70B],[H01A],[H01B],[H02A],[H02B],[H02C],[H05A],[H05B],[H06Z],[H07A],[H07B],[H08A],[H08B],[H40Z],[H41A],[H41B],[H42A],[H42B],[H42C],[H60A],[H60B],[H60C],[H61A],[H61B],[H62A],[H62B],[H63A],[H63B],[H64A],[H64B],[I01Z],[I02A],[I02B],[I03A],[I03B],[I03C],[I04Z],[I05Z],[I06Z],[I07Z],[I08A],[I08B],[I09A],[I09B],[I10A],[I10B],[I11Z],[I12A],[I12B],[I12C],[I13A],[I13B],[I13C],[I14Z],[I15Z],[I16Z],[I17Z],[I18Z],[I19Z],[I20Z],[I21Z],[I23Z],[I24Z],[I25Z],[I27A],[I27B],[I28A],[I28B],[I29Z],[I30Z],[I60Z],[I61Z],[I63Z],[I64A],[I64B],[I65A],[I65B],[I66A],[I66B],[I67A],[I67B],[I68A],[I68B],[I68C],[I69A],[I69B],[I69C],[I70Z],[I71A],[I71B],[I71C],[I72A],[I72B],[I73A],[I73B],[I73C],[I74A],[I74B],[I74C],[I75A],[I75B],[I75C],[I76A],[I76B],[I76C],[I77A],[I77B],[I78A],[I78B],[J01Z],[J06A],[J06B],[J07A],[J07B],[J08A],[J08B],[J09Z],[J10Z],[J11Z],[J12A],[J12B],[J12C],[J13A],[J13B],[J14Z],[J60A],[J60B],[J62A],[J62B],[J63Z],[J64A],[J64B],[J65A],[J65B],[J67A],[J67B],[J68A],[J68B],[K01Z],[K02Z],[K03Z],[K04Z],[K05Z],[K06Z],[K07Z],[K08Z],[K09Z],[K40Z],[K60A],[K60B],[K61Z],[K62A],[K62B],[K62C],[K63Z],[K64A],[K64B],[L02A],[L02B],[L03A],[L03B],[L04A],[L04B],[L04C],[L05A],[L05B],[L06A],[L06B],[L07A],[L07B],[L08A],[L08B],[L09A],[L09B],[L09C],[L40Z],[L41Z],[L42Z],[L60A],[L60B],[L60C],[L61Z],[L62A],[L62B],[L63A],[L63B],[L63C],[L64Z],[L65A],[L65B],[L66Z],[L67A],[L67B],[L67C],[M01Z],[M02A],[M02B],[M03A],[M03B],[M04A],[M04B],[M05Z],[M06A],[M06B],[M40Z],[M60A],[M60B],[M61A],[M61B],[M62A],[M62B],[M63Z],[M64Z],[N01Z],[N02A],[N02B],[N03A],[N03B],[N04Z],[N05A],[N05B],[N06Z],[N07Z],[N08Z],[N09Z],[N10Z],[N11A],[N11B],[N60A],[N60B],[N61Z],[N62A],[N62B],[O01A],[O01B],[O01C],[O02A],[O02B],[O03Z],[O04Z],[O05Z],[O60A],[O60B],[O60C],[O61Z],[O63Z],[O64A],[O64B],[O66A],[O66B],[P01Z],[P02Z],[P03Z],[P04Z],[P05Z],[P06A],[P06B],[P60A],[P60B],[P61Z],[P62Z],[P63Z],[P64Z],[P65A],[P65B],[P65C],[P65D],[P66A],[P66B],[P66C],[P66D],[P67A],[P67B],[P67C],[P67D],[Q01Z],[Q02A],[Q02B],[Q60A],[Q60B],[Q60C],[Q61A],[Q61B],[Q61C],[Q62Z],[R01A],[R01B],[R02A],[R02B],[R03A],[R03B],[R04A],[R04B],[R60A],[R60B],[R60C],[R61A],[R61B],[R61C],[R62A],[R62B],[R63Z],[R64Z],[S60Z],[S65A],[S65B],[S65C],[T01A],[T01B],[T01C],[T60A],[T60B],[T61A],[T61B],[T62A],[T62B],[T63A],[T63B],[T64A],[T64B],[U40Z],[U60Z],[U61A],[U61B],[U62A],[U62B],[U63A],[U63B],[U64Z],[U65Z],[U66Z],[U67Z],[U68Z],[V60A],[V60B],[V61Z],[V62A],[V62B],[V63A],[V63B],[V64Z],[W01Z],[W02Z],[W03Z],[W04Z],[W60Z],[W61Z],[X02Z],[X04A],[X04B],[X05Z],[X06A],[X06B],[X07A],[X07B],[X60A],[X60B],[X60C],[X61Z],[X62A],[X62B],[X63A],[X63B],[X64A],[X64B],[Y01Z],[Y02A],[Y02B],[Y03Z],[Y60Z],[Y61Z],[Y62A],[Y62B],[Z01A],[Z01B],[Z40Z],[Z60A],[Z60B],[Z60C],[Z61Z],[Z62Z],[Z63A],[Z63B],[Z64A],[Z64B],[Z65Z],[901Z],[902Z],[903Z],[960Z],[961Z],[963Z])
) AS pvt
But in this code every DRG come with zero values.
How can we do this with SQL Server?
just in place of [DRG] put [DRGCount]
SELECT TOP 1000 HospitalCode,Durum,[A01Z],[A03Z],[A05Z],[Z99A],[Z98A],[Z97A],[Z96A],[A06Z],[A07Z],[A08A],[A08B],[A09A],[A09B],[A40Z],[A41A],[A41B],[B01Z],[B02A],[B02B],[B02C],[B03A],[B03B],[B04A],[B04B],[B05Z],[B06A],[B06B],[B07A],[B07B],[B40Z],[B41Z],[B60A],[B60B],[B61A],[B61B],[B62Z],[B63Z],[B64A],[B64B],[B65Z],[B66A],[B66B],[B67A],[B67B],[B67C],[B68A],[B68B],[B69A],[B69B],[B70A],[B70B],[B70C],[B70D],[B71A],[B71B],[B72A],[B72B],[B73Z],[B74Z],[B75Z],[B76A],[B76B],[B77Z],[B78A],[B78B],[B79Z],[B80Z],[B81A],[B81B],[C01Z],[C02Z],[C03Z],[C04Z],[C05Z],[C10Z],[C11Z],[C12Z],[C13Z],[C14Z],[C15A],[C15B],[C16A],[C16B],[C60A],[C60B],[C61Z],[C62Z],[C63A],[C63B],[D01Z],[D02A],[D02B],[D02C],[D03Z],[D04A],[D04B],[D05Z],[D06Z],[D09Z],[D10Z],[D11Z],[D12Z],[D13Z],[D14Z],[D40Z],[D60A],[D60B],[D61Z],[D62Z],[D63A],[D63B],[D64Z],[D65Z],[D66A],[D66B],[D67A],[D67B],[E01A],[E01B],[E02A],[E02B],[E02C],[E40Z],[E41Z],[E60A],[E60B],[E61A],[E61B],[E62A],[E62B],[E62C],[E63Z],[E64Z],[E65A],[E65B],[E66A],[E66B],[E66C],[E67A],[E67B],[E68Z],[E69A],[E69B],[E69C],[E70A],[E70B],[E71A],[E71B],[E71C],[E72Z],[E73A],[E73B],[E73C],[E74A],[E74B],[E74C],[E75A],[E75B],[E75C],[F01A],[F01B],[F02Z],[F03Z],[F04A],[F04B],[F05A],[F05B],[F06A],[F06B],[F07A],[F07B],[F08A],[F08B],[F09A],[F09B],[F10Z],[F11A],[F11B],[F12Z],[F13Z],[F14A],[F14B],[F14C],[F15Z],[F16Z],[F17Z],[F18Z],[F19Z],[F20Z],[F21A],[F21B],[F40Z],[F41A],[F41B],[F42A],[F42B],[F60A],[F60B],[F60C],[F61Z],[F62A],[F62B],[F63A],[F63B],[F64Z],[F65A],[F65B],[F66A],[F66B],[F67A],[F67B],[F68Z],[F69A],[F69B],[F70A],[F70B],[F71A],[F71B],[F72A],[F72B],[F73A],[F73B],[F74Z],[F75A],[F75B],[F75C],[G01A],[G01B],[G02A],[G02B],[G03A],[G03B],[G03C],[G04A],[G04B],[G04C],[G05A],[G05B],[G06Z],[G07A],[G07B],[G08A],[G08B],[G09Z],[G10Z],[G11A],[G11B],[G12A],[G12B],[G42A],[G42B],[G43Z],[G44A],[G44B],[G44C],[G45A],[G45B],[G46A],[G46B],[G46C],[G60A],[G60B],[G61A],[G61B],[G62Z],[G63Z],[G64Z],[G65A],[G65B],[G66A],[G66B],[G67A],[G67B],[G68A],[G68B],[G69Z],[G70A],[G70B],[H01A],[H01B],[H02A],[H02B],[H02C],[H05A],[H05B],[H06Z],[H07A],[H07B],[H08A],[H08B],[H40Z],[H41A],[H41B],[H42A],[H42B],[H42C],[H60A],[H60B],[H60C],[H61A],[H61B],[H62A],[H62B],[H63A],[H63B],[H64A],[H64B],[I01Z],[I02A],[I02B],[I03A],[I03B],[I03C],[I04Z],[I05Z],[I06Z],[I07Z],[I08A],[I08B],[I09A],[I09B],[I10A],[I10B],[I11Z],[I12A],[I12B],[I12C],[I13A],[I13B],[I13C],[I14Z],[I15Z],[I16Z],[I17Z],[I18Z],[I19Z],[I20Z],[I21Z],[I23Z],[I24Z],[I25Z],[I27A],[I27B],[I28A],[I28B],[I29Z],[I30Z],[I60Z],[I61Z],[I63Z],[I64A],[I64B],[I65A],[I65B],[I66A],[I66B],[I67A],[I67B],[I68A],[I68B],[I68C],[I69A],[I69B],[I69C],[I70Z],[I71A],[I71B],[I71C],[I72A],[I72B],[I73A],[I73B],[I73C],[I74A],[I74B],[I74C],[I75A],[I75B],[I75C],[I76A],[I76B],[I76C],[I77A],[I77B],[I78A],[I78B],[J01Z],[J06A],[J06B],[J07A],[J07B],[J08A],[J08B],[J09Z],[J10Z],[J11Z],[J12A],[J12B],[J12C],[J13A],[J13B],[J14Z],[J60A],[J60B],[J62A],[J62B],[J63Z],[J64A],[J64B],[J65A],[J65B],[J67A],[J67B],[J68A],[J68B],[K01Z],[K02Z],[K03Z],[K04Z],[K05Z],[K06Z],[K07Z],[K08Z],[K09Z],[K40Z],[K60A],[K60B],[K61Z],[K62A],[K62B],[K62C],[K63Z],[K64A],[K64B],[L02A],[L02B],[L03A],[L03B],[L04A],[L04B],[L04C],[L05A],[L05B],[L06A],[L06B],[L07A],[L07B],[L08A],[L08B],[L09A],[L09B],[L09C],[L40Z],[L41Z],[L42Z],[L60A],[L60B],[L60C],[L61Z],[L62A],[L62B],[L63A],[L63B],[L63C],[L64Z],[L65A],[L65B],[L66Z],[L67A],[L67B],[L67C],[M01Z],[M02A],[M02B],[M03A],[M03B],[M04A],[M04B],[M05Z],[M06A],[M06B],[M40Z],[M60A],[M60B],[M61A],[M61B],[M62A],[M62B],[M63Z],[M64Z],[N01Z],[N02A],[N02B],[N03A],[N03B],[N04Z],[N05A],[N05B],[N06Z],[N07Z],[N08Z],[N09Z],[N10Z],[N11A],[N11B],[N60A],[N60B],[N61Z],[N62A],[N62B],[O01A],[O01B],[O01C],[O02A],[O02B],[O03Z],[O04Z],[O05Z],[O60A],[O60B],[O60C],[O61Z],[O63Z],[O64A],[O64B],[O66A],[O66B],[P01Z],[P02Z],[P03Z],[P04Z],[P05Z],[P06A],[P06B],[P60A],[P60B],[P61Z],[P62Z],[P63Z],[P64Z],[P65A],[P65B],[P65C],[P65D],[P66A],[P66B],[P66C],[P66D],[P67A],[P67B],[P67C],[P67D],[Q01Z],[Q02A],[Q02B],[Q60A],[Q60B],[Q60C],[Q61A],[Q61B],[Q61C],[Q62Z],[R01A],[R01B],[R02A],[R02B],[R03A],[R03B],[R04A],[R04B],[R60A],[R60B],[R60C],[R61A],[R61B],[R61C],[R62A],[R62B],[R63Z],[R64Z],[S60Z],[S65A],[S65B],[S65C],[T01A],[T01B],[T01C],[T60A],[T60B],[T61A],[T61B],[T62A],[T62B],[T63A],[T63B],[T64A],[T64B],[U40Z],[U60Z],[U61A],[U61B],[U62A],[U62B],[U63A],[U63B],[U64Z],[U65Z],[U66Z],[U67Z],[U68Z],[V60A],[V60B],[V61Z],[V62A],[V62B],[V63A],[V63B],[V64Z],[W01Z],[W02Z],[W03Z],[W04Z],[W60Z],[W61Z],[X02Z],[X04A],[X04B],[X05Z],[X06A],[X06B],[X07A],[X07B],[X60A],[X60B],[X60C],[X61Z],[X62A],[X62B],[X63A],[X63B],[X64A],[X64B],[Y01Z],[Y02A],[Y02B],[Y03Z],[Y60Z],[Y61Z],[Y62A],[Y62B],[Z01A],[Z01B],[Z40Z],[Z60A],[Z60B],[Z60C],[Z61Z],[Z62Z],[Z63A],[Z63B],[Z64A],[Z64B],[Z65Z],[901Z],[902Z],[903Z],[960Z],[961Z],[963Z]
FROM
(SELECT * FROM TIGPatient) p
PIVOT
(
COUNT (DRGCount)
FOR DRG IN
( [A01Z],[A03Z],[A05Z],[Z99A],[Z98A],[Z97A],[Z96A],[A06Z],[A07Z],[A08A],[A08B],[A09A],[A09B],[A40Z],[A41A],[A41B],[B01Z],[B02A],[B02B],[B02C],[B03A],[B03B],[B04A],[B04B],[B05Z],[B06A],[B06B],[B07A],[B07B],[B40Z],[B41Z],[B60A],[B60B],[B61A],[B61B],[B62Z],[B63Z],[B64A],[B64B],[B65Z],[B66A],[B66B],[B67A],[B67B],[B67C],[B68A],[B68B],[B69A],[B69B],[B70A],[B70B],[B70C],[B70D],[B71A],[B71B],[B72A],[B72B],[B73Z],[B74Z],[B75Z],[B76A],[B76B],[B77Z],[B78A],[B78B],[B79Z],[B80Z],[B81A],[B81B],[C01Z],[C02Z],[C03Z],[C04Z],[C05Z],[C10Z],[C11Z],[C12Z],[C13Z],[C14Z],[C15A],[C15B],[C16A],[C16B],[C60A],[C60B],[C61Z],[C62Z],[C63A],[C63B],[D01Z],[D02A],[D02B],[D02C],[D03Z],[D04A],[D04B],[D05Z],[D06Z],[D09Z],[D10Z],[D11Z],[D12Z],[D13Z],[D14Z],[D40Z],[D60A],[D60B],[D61Z],[D62Z],[D63A],[D63B],[D64Z],[D65Z],[D66A],[D66B],[D67A],[D67B],[E01A],[E01B],[E02A],[E02B],[E02C],[E40Z],[E41Z],[E60A],[E60B],[E61A],[E61B],[E62A],[E62B],[E62C],[E63Z],[E64Z],[E65A],[E65B],[E66A],[E66B],[E66C],[E67A],[E67B],[E68Z],[E69A],[E69B],[E69C],[E70A],[E70B],[E71A],[E71B],[E71C],[E72Z],[E73A],[E73B],[E73C],[E74A],[E74B],[E74C],[E75A],[E75B],[E75C],[F01A],[F01B],[F02Z],[F03Z],[F04A],[F04B],[F05A],[F05B],[F06A],[F06B],[F07A],[F07B],[F08A],[F08B],[F09A],[F09B],[F10Z],[F11A],[F11B],[F12Z],[F13Z],[F14A],[F14B],[F14C],[F15Z],[F16Z],[F17Z],[F18Z],[F19Z],[F20Z],[F21A],[F21B],[F40Z],[F41A],[F41B],[F42A],[F42B],[F60A],[F60B],[F60C],[F61Z],[F62A],[F62B],[F63A],[F63B],[F64Z],[F65A],[F65B],[F66A],[F66B],[F67A],[F67B],[F68Z],[F69A],[F69B],[F70A],[F70B],[F71A],[F71B],[F72A],[F72B],[F73A],[F73B],[F74Z],[F75A],[F75B],[F75C],[G01A],[G01B],[G02A],[G02B],[G03A],[G03B],[G03C],[G04A],[G04B],[G04C],[G05A],[G05B],[G06Z],[G07A],[G07B],[G08A],[G08B],[G09Z],[G10Z],[G11A],[G11B],[G12A],[G12B],[G42A],[G42B],[G43Z],[G44A],[G44B],[G44C],[G45A],[G45B],[G46A],[G46B],[G46C],[G60A],[G60B],[G61A],[G61B],[G62Z],[G63Z],[G64Z],[G65A],[G65B],[G66A],[G66B],[G67A],[G67B],[G68A],[G68B],[G69Z],[G70A],[G70B],[H01A],[H01B],[H02A],[H02B],[H02C],[H05A],[H05B],[H06Z],[H07A],[H07B],[H08A],[H08B],[H40Z],[H41A],[H41B],[H42A],[H42B],[H42C],[H60A],[H60B],[H60C],[H61A],[H61B],[H62A],[H62B],[H63A],[H63B],[H64A],[H64B],[I01Z],[I02A],[I02B],[I03A],[I03B],[I03C],[I04Z],[I05Z],[I06Z],[I07Z],[I08A],[I08B],[I09A],[I09B],[I10A],[I10B],[I11Z],[I12A],[I12B],[I12C],[I13A],[I13B],[I13C],[I14Z],[I15Z],[I16Z],[I17Z],[I18Z],[I19Z],[I20Z],[I21Z],[I23Z],[I24Z],[I25Z],[I27A],[I27B],[I28A],[I28B],[I29Z],[I30Z],[I60Z],[I61Z],[I63Z],[I64A],[I64B],[I65A],[I65B],[I66A],[I66B],[I67A],[I67B],[I68A],[I68B],[I68C],[I69A],[I69B],[I69C],[I70Z],[I71A],[I71B],[I71C],[I72A],[I72B],[I73A],[I73B],[I73C],[I74A],[I74B],[I74C],[I75A],[I75B],[I75C],[I76A],[I76B],[I76C],[I77A],[I77B],[I78A],[I78B],[J01Z],[J06A],[J06B],[J07A],[J07B],[J08A],[J08B],[J09Z],[J10Z],[J11Z],[J12A],[J12B],[J12C],[J13A],[J13B],[J14Z],[J60A],[J60B],[J62A],[J62B],[J63Z],[J64A],[J64B],[J65A],[J65B],[J67A],[J67B],[J68A],[J68B],[K01Z],[K02Z],[K03Z],[K04Z],[K05Z],[K06Z],[K07Z],[K08Z],[K09Z],[K40Z],[K60A],[K60B],[K61Z],[K62A],[K62B],[K62C],[K63Z],[K64A],[K64B],[L02A],[L02B],[L03A],[L03B],[L04A],[L04B],[L04C],[L05A],[L05B],[L06A],[L06B],[L07A],[L07B],[L08A],[L08B],[L09A],[L09B],[L09C],[L40Z],[L41Z],[L42Z],[L60A],[L60B],[L60C],[L61Z],[L62A],[L62B],[L63A],[L63B],[L63C],[L64Z],[L65A],[L65B],[L66Z],[L67A],[L67B],[L67C],[M01Z],[M02A],[M02B],[M03A],[M03B],[M04A],[M04B],[M05Z],[M06A],[M06B],[M40Z],[M60A],[M60B],[M61A],[M61B],[M62A],[M62B],[M63Z],[M64Z],[N01Z],[N02A],[N02B],[N03A],[N03B],[N04Z],[N05A],[N05B],[N06Z],[N07Z],[N08Z],[N09Z],[N10Z],[N11A],[N11B],[N60A],[N60B],[N61Z],[N62A],[N62B],[O01A],[O01B],[O01C],[O02A],[O02B],[O03Z],[O04Z],[O05Z],[O60A],[O60B],[O60C],[O61Z],[O63Z],[O64A],[O64B],[O66A],[O66B],[P01Z],[P02Z],[P03Z],[P04Z],[P05Z],[P06A],[P06B],[P60A],[P60B],[P61Z],[P62Z],[P63Z],[P64Z],[P65A],[P65B],[P65C],[P65D],[P66A],[P66B],[P66C],[P66D],[P67A],[P67B],[P67C],[P67D],[Q01Z],[Q02A],[Q02B],[Q60A],[Q60B],[Q60C],[Q61A],[Q61B],[Q61C],[Q62Z],[R01A],[R01B],[R02A],[R02B],[R03A],[R03B],[R04A],[R04B],[R60A],[R60B],[R60C],[R61A],[R61B],[R61C],[R62A],[R62B],[R63Z],[R64Z],[S60Z],[S65A],[S65B],[S65C],[T01A],[T01B],[T01C],[T60A],[T60B],[T61A],[T61B],[T62A],[T62B],[T63A],[T63B],[T64A],[T64B],[U40Z],[U60Z],[U61A],[U61B],[U62A],[U62B],[U63A],[U63B],[U64Z],[U65Z],[U66Z],[U67Z],[U68Z],[V60A],[V60B],[V61Z],[V62A],[V62B],[V63A],[V63B],[V64Z],[W01Z],[W02Z],[W03Z],[W04Z],[W60Z],[W61Z],[X02Z],[X04A],[X04B],[X05Z],[X06A],[X06B],[X07A],[X07B],[X60A],[X60B],[X60C],[X61Z],[X62A],[X62B],[X63A],[X63B],[X64A],[X64B],[Y01Z],[Y02A],[Y02B],[Y03Z],[Y60Z],[Y61Z],[Y62A],[Y62B],[Z01A],[Z01B],[Z40Z],[Z60A],[Z60B],[Z60C],[Z61Z],[Z62Z],[Z63A],[Z63B],[Z64A],[Z64B],[Z65Z],[901Z],[902Z],[903Z],[960Z],[961Z],[963Z])
) AS pvt
This can be done using a Dynamic Crosstab.
Read this article by Jeff Moden for reference: http://www.sqlservercentral.com/articles/Crosstab/65048
DECLARE #sql1 VARCHAR(2000) = ''
DECLARE #sql2 VARCHAR(2000) = ''
DECLARE #sql3 VARCHAR(2000) = ''
SELECT #sql1 =
'SELECT
HospitalName
'
SELECT #sql2 = #sql2 +
' ,MAX(CASE WHEN DRG = ''' + DRG + ''' THEN DrgCount ELSE 0 END) AS [' + DRG + ']' + CHAR(10)
FROM(
SELECT DISTINCT DRG FROM temp
)t
ORDER BY DRG
SELECT #sql3 =
'FROM temp
GROUP BY HospitalName
ORDER BY HospitalName'
PRINT (#sql1 + #sql2 + #sql3)
EXEC (#sql1 + #sql2 + #sql3)
SELECT [HospitalName], [F67A], [F68A], [F69A], [F60A], [F61A] FROM tbl
PIVOT(
COUNT([DRG])
FOR [DRG] IN ([F67A], [F68A], [F69A], [F60A], [F61A])
) AS p
SQLFiddle
As for your query :
Remove Durum field from the SELECT ;
No need for a temporary table (SELECT * FROM TIGPatient) p;
So the following should work :
SELECT TOP 1000 HospitalCode
,[A01Z],[A03Z],[A05Z],[Z99A],[Z98A],[Z97A],[Z96A],[A06Z],[A07Z],[A08A],[A08B],[A09A],[A09B],[A40Z],[A41A],[A41B],[B01Z],[B02A],[B02B],[B02C],[B03A],[B03B],[B04A],[B04B],[B05Z],[B06A],[B06B],[B07A],[B07B],[B40Z],[B41Z],[B60A],[B60B],[B61A],[B61B],[B62Z],[B63Z],[B64A],[B64B],[B65Z],[B66A],[B66B],[B67A],[B67B],[B67C],[B68A],[B68B],[B69A],[B69B],[B70A],[B70B],[B70C],[B70D],[B71A],[B71B],[B72A],[B72B],[B73Z],[B74Z],[B75Z],[B76A],[B76B],[B77Z],[B78A],[B78B],[B79Z],[B80Z],[B81A],[B81B],[C01Z],[C02Z],[C03Z],[C04Z],[C05Z],[C10Z],[C11Z],[C12Z],[C13Z],[C14Z],[C15A],[C15B],[C16A],[C16B],[C60A],[C60B],[C61Z],[C62Z],[C63A],[C63B],[D01Z],[D02A],[D02B],[D02C],[D03Z],[D04A],[D04B],[D05Z],[D06Z],[D09Z],[D10Z],[D11Z],[D12Z],[D13Z],[D14Z],[D40Z],[D60A],[D60B],[D61Z],[D62Z],[D63A],[D63B],[D64Z],[D65Z],[D66A],[D66B],[D67A],[D67B],[E01A],[E01B],[E02A],[E02B],[E02C],[E40Z],[E41Z],[E60A],[E60B],[E61A],[E61B],[E62A],[E62B],[E62C],[E63Z],[E64Z],[E65A],[E65B],[E66A],[E66B],[E66C],[E67A],[E67B],[E68Z],[E69A],[E69B],[E69C],[E70A],[E70B],[E71A],[E71B],[E71C],[E72Z],[E73A],[E73B],[E73C],[E74A],[E74B],[E74C],[E75A],[E75B],[E75C],[F01A],[F01B],[F02Z],[F03Z],[F04A],[F04B],[F05A],[F05B],[F06A],[F06B],[F07A],[F07B],[F08A],[F08B],[F09A],[F09B],[F10Z],[F11A],[F11B],[F12Z],[F13Z],[F14A],[F14B],[F14C],[F15Z],[F16Z],[F17Z],[F18Z],[F19Z],[F20Z],[F21A],[F21B],[F40Z],[F41A],[F41B],[F42A],[F42B],[F60A],[F60B],[F60C],[F61Z],[F62A],[F62B],[F63A],[F63B],[F64Z],[F65A],[F65B],[F66A],[F66B],[F67A],[F67B],[F68Z],[F69A],[F69B],[F70A],[F70B],[F71A],[F71B],[F72A],[F72B],[F73A],[F73B],[F74Z],[F75A],[F75B],[F75C],[G01A],[G01B],[G02A],[G02B],[G03A],[G03B],[G03C],[G04A],[G04B],[G04C],[G05A],[G05B],[G06Z],[G07A],[G07B],[G08A],[G08B],[G09Z],[G10Z],[G11A],[G11B],[G12A],[G12B],[G42A],[G42B],[G43Z],[G44A],[G44B],[G44C],[G45A],[G45B],[G46A],[G46B],[G46C],[G60A],[G60B],[G61A],[G61B],[G62Z],[G63Z],[G64Z],[G65A],[G65B],[G66A],[G66B],[G67A],[G67B],[G68A],[G68B],[G69Z],[G70A],[G70B],[H01A],[H01B],[H02A],[H02B],[H02C],[H05A],[H05B],[H06Z],[H07A],[H07B],[H08A],[H08B],[H40Z],[H41A],[H41B],[H42A],[H42B],[H42C],[H60A],[H60B],[H60C],[H61A],[H61B],[H62A],[H62B],[H63A],[H63B],[H64A],[H64B],[I01Z],[I02A],[I02B],[I03A],[I03B],[I03C],[I04Z],[I05Z],[I06Z],[I07Z],[I08A],[I08B],[I09A],[I09B],[I10A],[I10B],[I11Z],[I12A],[I12B],[I12C],[I13A],[I13B],[I13C],[I14Z],[I15Z],[I16Z],[I17Z],[I18Z],[I19Z],[I20Z],[I21Z],[I23Z],[I24Z],[I25Z],[I27A],[I27B],[I28A],[I28B],[I29Z],[I30Z],[I60Z],[I61Z],[I63Z],[I64A],[I64B],[I65A],[I65B],[I66A],[I66B],[I67A],[I67B],[I68A],[I68B],[I68C],[I69A],[I69B],[I69C],[I70Z],[I71A],[I71B],[I71C],[I72A],[I72B],[I73A],[I73B],[I73C],[I74A],[I74B],[I74C],[I75A],[I75B],[I75C],[I76A],[I76B],[I76C],[I77A],[I77B],[I78A],[I78B],[J01Z],[J06A],[J06B],[J07A],[J07B],[J08A],[J08B],[J09Z],[J10Z],[J11Z],[J12A],[J12B],[J12C],[J13A],[J13B],[J14Z],[J60A],[J60B],[J62A],[J62B],[J63Z],[J64A],[J64B],[J65A],[J65B],[J67A],[J67B],[J68A],[J68B],[K01Z],[K02Z],[K03Z],[K04Z],[K05Z],[K06Z],[K07Z],[K08Z],[K09Z],[K40Z],[K60A],[K60B],[K61Z],[K62A],[K62B],[K62C],[K63Z],[K64A],[K64B],[L02A],[L02B],[L03A],[L03B],[L04A],[L04B],[L04C],[L05A],[L05B],[L06A],[L06B],[L07A],[L07B],[L08A],[L08B],[L09A],[L09B],[L09C],[L40Z],[L41Z],[L42Z],[L60A],[L60B],[L60C],[L61Z],[L62A],[L62B],[L63A],[L63B],[L63C],[L64Z],[L65A],[L65B],[L66Z],[L67A],[L67B],[L67C],[M01Z],[M02A],[M02B],[M03A],[M03B],[M04A],[M04B],[M05Z],[M06A],[M06B],[M40Z],[M60A],[M60B],[M61A],[M61B],[M62A],[M62B],[M63Z],[M64Z],[N01Z],[N02A],[N02B],[N03A],[N03B],[N04Z],[N05A],[N05B],[N06Z],[N07Z],[N08Z],[N09Z],[N10Z],[N11A],[N11B],[N60A],[N60B],[N61Z],[N62A],[N62B],[O01A],[O01B],[O01C],[O02A],[O02B],[O03Z],[O04Z],[O05Z],[O60A],[O60B],[O60C],[O61Z],[O63Z],[O64A],[O64B],[O66A],[O66B],[P01Z],[P02Z],[P03Z],[P04Z],[P05Z],[P06A],[P06B],[P60A],[P60B],[P61Z],[P62Z],[P63Z],[P64Z],[P65A],[P65B],[P65C],[P65D],[P66A],[P66B],[P66C],[P66D],[P67A],[P67B],[P67C],[P67D],[Q01Z],[Q02A],[Q02B],[Q60A],[Q60B],[Q60C],[Q61A],[Q61B],[Q61C],[Q62Z],[R01A],[R01B],[R02A],[R02B],[R03A],[R03B],[R04A],[R04B],[R60A],[R60B],[R60C],[R61A],[R61B],[R61C],[R62A],[R62B],[R63Z],[R64Z],[S60Z],[S65A],[S65B],[S65C],[T01A],[T01B],[T01C],[T60A],[T60B],[T61A],[T61B],[T62A],[T62B],[T63A],[T63B],[T64A],[T64B],[U40Z],[U60Z],[U61A],[U61B],[U62A],[U62B],[U63A],[U63B],[U64Z],[U65Z],[U66Z],[U67Z],[U68Z],[V60A],[V60B],[V61Z],[V62A],[V62B],[V63A],[V63B],[V64Z],[W01Z],[W02Z],[W03Z],[W04Z],[W60Z],[W61Z],[X02Z],[X04A],[X04B],[X05Z],[X06A],[X06B],[X07A],[X07B],[X60A],[X60B],[X60C],[X61Z],[X62A],[X62B],[X63A],[X63B],[X64A],[X64B],[Y01Z],[Y02A],[Y02B],[Y03Z],[Y60Z],[Y61Z],[Y62A],[Y62B],[Z01A],[Z01B],[Z40Z],[Z60A],[Z60B],[Z60C],[Z61Z],[Z62Z],[Z63A],[Z63B],[Z64A],[Z64B],[Z65Z],[901Z],[902Z],[903Z],[960Z],[961Z],[963Z]
FROM TIGPatient
PIVOT (
COUNT (DRG)
FOR DRG IN([A01Z],[A03Z],[A05Z],[Z99A],[Z98A],[Z97A],[Z96A],[A06Z],[A07Z],[A08A],[A08B],[A09A],[A09B],[A40Z],[A41A],[A41B],[B01Z],[B02A],[B02B],[B02C],[B03A],[B03B],[B04A],[B04B],[B05Z],[B06A],[B06B],[B07A],[B07B],[B40Z],[B41Z],[B60A],[B60B],[B61A],[B61B],[B62Z],[B63Z],[B64A],[B64B],[B65Z],[B66A],[B66B],[B67A],[B67B],[B67C],[B68A],[B68B],[B69A],[B69B],[B70A],[B70B],[B70C],[B70D],[B71A],[B71B],[B72A],[B72B],[B73Z],[B74Z],[B75Z],[B76A],[B76B],[B77Z],[B78A],[B78B],[B79Z],[B80Z],[B81A],[B81B],[C01Z],[C02Z],[C03Z],[C04Z],[C05Z],[C10Z],[C11Z],[C12Z],[C13Z],[C14Z],[C15A],[C15B],[C16A],[C16B],[C60A],[C60B],[C61Z],[C62Z],[C63A],[C63B],[D01Z],[D02A],[D02B],[D02C],[D03Z],[D04A],[D04B],[D05Z],[D06Z],[D09Z],[D10Z],[D11Z],[D12Z],[D13Z],[D14Z],[D40Z],[D60A],[D60B],[D61Z],[D62Z],[D63A],[D63B],[D64Z],[D65Z],[D66A],[D66B],[D67A],[D67B],[E01A],[E01B],[E02A],[E02B],[E02C],[E40Z],[E41Z],[E60A],[E60B],[E61A],[E61B],[E62A],[E62B],[E62C],[E63Z],[E64Z],[E65A],[E65B],[E66A],[E66B],[E66C],[E67A],[E67B],[E68Z],[E69A],[E69B],[E69C],[E70A],[E70B],[E71A],[E71B],[E71C],[E72Z],[E73A],[E73B],[E73C],[E74A],[E74B],[E74C],[E75A],[E75B],[E75C],[F01A],[F01B],[F02Z],[F03Z],[F04A],[F04B],[F05A],[F05B],[F06A],[F06B],[F07A],[F07B],[F08A],[F08B],[F09A],[F09B],[F10Z],[F11A],[F11B],[F12Z],[F13Z],[F14A],[F14B],[F14C],[F15Z],[F16Z],[F17Z],[F18Z],[F19Z],[F20Z],[F21A],[F21B],[F40Z],[F41A],[F41B],[F42A],[F42B],[F60A],[F60B],[F60C],[F61Z],[F62A],[F62B],[F63A],[F63B],[F64Z],[F65A],[F65B],[F66A],[F66B],[F67A],[F67B],[F68Z],[F69A],[F69B],[F70A],[F70B],[F71A],[F71B],[F72A],[F72B],[F73A],[F73B],[F74Z],[F75A],[F75B],[F75C],[G01A],[G01B],[G02A],[G02B],[G03A],[G03B],[G03C],[G04A],[G04B],[G04C],[G05A],[G05B],[G06Z],[G07A],[G07B],[G08A],[G08B],[G09Z],[G10Z],[G11A],[G11B],[G12A],[G12B],[G42A],[G42B],[G43Z],[G44A],[G44B],[G44C],[G45A],[G45B],[G46A],[G46B],[G46C],[G60A],[G60B],[G61A],[G61B],[G62Z],[G63Z],[G64Z],[G65A],[G65B],[G66A],[G66B],[G67A],[G67B],[G68A],[G68B],[G69Z],[G70A],[G70B],[H01A],[H01B],[H02A],[H02B],[H02C],[H05A],[H05B],[H06Z],[H07A],[H07B],[H08A],[H08B],[H40Z],[H41A],[H41B],[H42A],[H42B],[H42C],[H60A],[H60B],[H60C],[H61A],[H61B],[H62A],[H62B],[H63A],[H63B],[H64A],[H64B],[I01Z],[I02A],[I02B],[I03A],[I03B],[I03C],[I04Z],[I05Z],[I06Z],[I07Z],[I08A],[I08B],[I09A],[I09B],[I10A],[I10B],[I11Z],[I12A],[I12B],[I12C],[I13A],[I13B],[I13C],[I14Z],[I15Z],[I16Z],[I17Z],[I18Z],[I19Z],[I20Z],[I21Z],[I23Z],[I24Z],[I25Z],[I27A],[I27B],[I28A],[I28B],[I29Z],[I30Z],[I60Z],[I61Z],[I63Z],[I64A],[I64B],[I65A],[I65B],[I66A],[I66B],[I67A],[I67B],[I68A],[I68B],[I68C],[I69A],[I69B],[I69C],[I70Z],[I71A],[I71B],[I71C],[I72A],[I72B],[I73A],[I73B],[I73C],[I74A],[I74B],[I74C],[I75A],[I75B],[I75C],[I76A],[I76B],[I76C],[I77A],[I77B],[I78A],[I78B],[J01Z],[J06A],[J06B],[J07A],[J07B],[J08A],[J08B],[J09Z],[J10Z],[J11Z],[J12A],[J12B],[J12C],[J13A],[J13B],[J14Z],[J60A],[J60B],[J62A],[J62B],[J63Z],[J64A],[J64B],[J65A],[J65B],[J67A],[J67B],[J68A],[J68B],[K01Z],[K02Z],[K03Z],[K04Z],[K05Z],[K06Z],[K07Z],[K08Z],[K09Z],[K40Z],[K60A],[K60B],[K61Z],[K62A],[K62B],[K62C],[K63Z],[K64A],[K64B],[L02A],[L02B],[L03A],[L03B],[L04A],[L04B],[L04C],[L05A],[L05B],[L06A],[L06B],[L07A],[L07B],[L08A],[L08B],[L09A],[L09B],[L09C],[L40Z],[L41Z],[L42Z],[L60A],[L60B],[L60C],[L61Z],[L62A],[L62B],[L63A],[L63B],[L63C],[L64Z],[L65A],[L65B],[L66Z],[L67A],[L67B],[L67C],[M01Z],[M02A],[M02B],[M03A],[M03B],[M04A],[M04B],[M05Z],[M06A],[M06B],[M40Z],[M60A],[M60B],[M61A],[M61B],[M62A],[M62B],[M63Z],[M64Z],[N01Z],[N02A],[N02B],[N03A],[N03B],[N04Z],[N05A],[N05B],[N06Z],[N07Z],[N08Z],[N09Z],[N10Z],[N11A],[N11B],[N60A],[N60B],[N61Z],[N62A],[N62B],[O01A],[O01B],[O01C],[O02A],[O02B],[O03Z],[O04Z],[O05Z],[O60A],[O60B],[O60C],[O61Z],[O63Z],[O64A],[O64B],[O66A],[O66B],[P01Z],[P02Z],[P03Z],[P04Z],[P05Z],[P06A],[P06B],[P60A],[P60B],[P61Z],[P62Z],[P63Z],[P64Z],[P65A],[P65B],[P65C],[P65D],[P66A],[P66B],[P66C],[P66D],[P67A],[P67B],[P67C],[P67D],[Q01Z],[Q02A],[Q02B],[Q60A],[Q60B],[Q60C],[Q61A],[Q61B],[Q61C],[Q62Z],[R01A],[R01B],[R02A],[R02B],[R03A],[R03B],[R04A],[R04B],[R60A],[R60B],[R60C],[R61A],[R61B],[R61C],[R62A],[R62B],[R63Z],[R64Z],[S60Z],[S65A],[S65B],[S65C],[T01A],[T01B],[T01C],[T60A],[T60B],[T61A],[T61B],[T62A],[T62B],[T63A],[T63B],[T64A],[T64B],[U40Z],[U60Z],[U61A],[U61B],[U62A],[U62B],[U63A],[U63B],[U64Z],[U65Z],[U66Z],[U67Z],[U68Z],[V60A],[V60B],[V61Z],[V62A],[V62B],[V63A],[V63B],[V64Z],[W01Z],[W02Z],[W03Z],[W04Z],[W60Z],[W61Z],[X02Z],[X04A],[X04B],[X05Z],[X06A],[X06B],[X07A],[X07B],[X60A],[X60B],[X60C],[X61Z],[X62A],[X62B],[X63A],[X63B],[X64A],[X64B],[Y01Z],[Y02A],[Y02B],[Y03Z],[Y60Z],[Y61Z],[Y62A],[Y62B],[Z01A],[Z01B],[Z40Z],[Z60A],[Z60B],[Z60C],[Z61Z],[Z62Z],[Z63A],[Z63B],[Z64A],[Z64B],[Z65Z],[901Z],[902Z],[903Z],[960Z],[961Z],[963Z])
) AS p