gilas
gilas

Reputation: 43

How to merge rows in one using SQL Server 2008

I have a SQL query like this

enter image description here

What I want is showing one row and adding columns dynamically

Like this:

enter image description here

How can I do that?

Upvotes: 0

Views: 60

Answers (1)

mehdi lotfi
mehdi lotfi

Reputation: 11571

you must using pivot query.

SELECT cotation_study_uid, contation_label,[OMNIPAQUE 350*50ML] AS col1, [Crane TDM] AS col2, [Annulation produit] AS col3
(SELECT *
FROM yourtable)p
PIVOT (SUM(contation_prix) FOR cotation_label IN ('OMNIPAQUE 350*50ML', 'Crane TDM', 'Annulation produit'))

Upvotes: 1

Related Questions