• Thank you for doing an excellent job of setting up the problem for us. Good job. Looking at the problem all you really wanted to do was pivot the the values in transmission_natlang. That was simple enough. But there may be problems producing the column titles you want.

    The code below will produce the results you want, but with several warnings:

    (1) The original sort order is lost because there is no column or set of columns in your original data to control the sequence of the final output. If that sequence is critical, add a column to control the sequence, take the MIN() value of it in the summary query, and sort by the resulting column with an Order By.

    (2) The case statements were created specifically for the two values presented in your sample data. This code will NOT automatically adapt itself to any other values.

    (3) Adding the column names '1,0 MPI 75 CV' was also done dynamically. Again, the code will not automatically adapt itself to new values.

    It appears that you want sql code to duplicate the functionality of a PIVOT in excel. SQL does not do have that capacity without coding more sophisticated dynamic SQL than I have time to create for you this morning. Perhaps someone else can pick this up and run with it. Good luck.

    ;with cte as (select technical_item_name_natlang, category_name_natlang

    ,case when transmission_natlang = 'Auto 5 vel.'

    then modeltrim_name else null end as cv1

    ,case when transmission_natlang = 'Manual 5 vel.'

    then modeltrim_name else null end as cv2

    from #urgent_2_11)

    select technical_item_name_natlang, category_name_natlang

    , isnull(max(cv1),'-') as '1,0 MPI 75 CV'

    , isnull(max(cv2),'-') as '1,0 MPI 75 CV'

    from cte

    group by technical_item_name_natlang, category_name_natlang

    Edited to add: Sorry Luis, I forgot you were already working on this with him. If you are already well into dynamic SQL, then the above code is WAY behind the curve.

    __________________________________________________

    Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
    Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills