Forum Discussion
Abdel1978
Nov 13, 2023Copper Contributor
Pivot and group table.
Hello Evevryone,
I have table Zipo with the following colomns:
RdvId int, WorkLineNumber int , WorkDescription nvarchar(250):
Example of data
RdvId | WorkLineNumber | WorkDescription |
1177 | 0 | Distribution - Remplcement kit Diesel |
1177 | 1 | Pneus - Forfait montage + équilibrage x 2 |
1177 | 2 | Freinage - Remplacement plaquettes AV |
1181 | 0 | Entretien des 180 000 km /Long Life Classique |
1181 | 1 | Pneus - Réparation x 1 |
I need to have data transformation as:
RdvId | Q1 | Q2 | Q3 |
1177 | Distribution - Remplcement kit Diesel | Pneus - Forfait montage + équilibrage x 2 | Freinage - Remplacement plaquettes AV |
1181 | Entretien des 180 000 km /Long Life Classique | Pneus - Réparation x 1 |
For the same RdvId
IF WorkLineNumber=0 THEN Q1 =WorkDescription
IF WorkLineNumber=1 THEN Q2 =WorkDescription
IF WorkLineNumber=2 THEN Q3 =WorkDescription
Thank you for help
- Abdel1978Copper Contributor
SELECT RdvId
,MAX(CASE WHEN WorkLineNumber = 0 THEN WorkDescription END) AS Q1
,MAX(CASE WHEN WorkLineNumber = 1 THEN WorkDescription END) AS Q2
,MAX(CASE WHEN WorkLineNumber = 2 THEN WorkDescription END) AS Q3 F
ROM #t
ROUP BY RdvId;