I believe I need a PIVOT Select statement, but I have never done it.
Here is what I have:
I have a TABLE_A where I can do:
[tt]
SELECT PN, IN_SEC
FROM TABLE_A
WHERE (PN = 'My_PN')
AND (STATUS = 'A')
[/tt]
[pre]
PN IN_SEC
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR, REL
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN TAC, REL
My_PN TAC, REL
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
[/pre]
I can ask separately to count how many times My_PN appears with each individual ‘IN_SEC’ piece:
[tt]
SELECT COUNT(PN) AS APR
FROM TABLE_A
WHERE (PN = 'My_PN')
AND (STATUS = 'A')
AND (IN_SEC LIKE '%[red]APR[/red]%')
[/tt]
I get: [red]41[/red]
[tt]
SELECT COUNT(PN) AS TAC
FROM TABLE_A
WHERE (PN = 'My_PN')
AND (STATUS = 'A')
AND (IN_SEC LIKE '%[blue]TAC[/blue]%')
[/tt]
I get: [blue]2[/blue]
[tt]
SELECT COUNT(PN) AS REL
FROM TABLE_A
WHERE (PN = 'My_PN')
AND (STATUS = 'A')
AND (IN_SEC LIKE '%[green]REL[/green]%')
[/tt]
I get: [green]3[/green]
I do have a table (MY_STATUS) where all those ‘pieces’ are listed like this:
[pre]
SELECT ID, ABBREV
FROM MY_STATUS
ORDER ID
ID ABBREV
1 DES
2 [red]APR[/red]
3 ACQ
4 CON
5 [blue]TAC[/blue]
6 PRP
7 [green]REL[/green]
8 R_R
9 CNF
[/pre]
What I am trying to get is something like this:
[pre]
PN DES [red]APR[/red] ACQ CON [blue]TAC[/blue] PRP [green]REL[/green] R_R CNF
My_PN 0 [red]41[/red] 0 0 [blue]2[/blue] 0 [green]3[/green] 0 0
[/pre]
All other fields where the count is zero could show 0 or nothing
Any pointers to the right place will be much appreciated.
Have fun.
---- Andy
Here is what I have:
I have a TABLE_A where I can do:
[tt]
SELECT PN, IN_SEC
FROM TABLE_A
WHERE (PN = 'My_PN')
AND (STATUS = 'A')
[/tt]
[pre]
PN IN_SEC
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR, REL
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN TAC, REL
My_PN TAC, REL
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
My_PN APR
[/pre]
I can ask separately to count how many times My_PN appears with each individual ‘IN_SEC’ piece:
[tt]
SELECT COUNT(PN) AS APR
FROM TABLE_A
WHERE (PN = 'My_PN')
AND (STATUS = 'A')
AND (IN_SEC LIKE '%[red]APR[/red]%')
[/tt]
I get: [red]41[/red]
[tt]
SELECT COUNT(PN) AS TAC
FROM TABLE_A
WHERE (PN = 'My_PN')
AND (STATUS = 'A')
AND (IN_SEC LIKE '%[blue]TAC[/blue]%')
[/tt]
I get: [blue]2[/blue]
[tt]
SELECT COUNT(PN) AS REL
FROM TABLE_A
WHERE (PN = 'My_PN')
AND (STATUS = 'A')
AND (IN_SEC LIKE '%[green]REL[/green]%')
[/tt]
I get: [green]3[/green]
I do have a table (MY_STATUS) where all those ‘pieces’ are listed like this:
[pre]
SELECT ID, ABBREV
FROM MY_STATUS
ORDER ID
ID ABBREV
1 DES
2 [red]APR[/red]
3 ACQ
4 CON
5 [blue]TAC[/blue]
6 PRP
7 [green]REL[/green]
8 R_R
9 CNF
[/pre]
What I am trying to get is something like this:
[pre]
PN DES [red]APR[/red] ACQ CON [blue]TAC[/blue] PRP [green]REL[/green] R_R CNF
My_PN 0 [red]41[/red] 0 0 [blue]2[/blue] 0 [green]3[/green] 0 0
[/pre]
All other fields where the count is zero could show 0 or nothing
Any pointers to the right place will be much appreciated.
Have fun.
---- Andy