I'm querying a table which holds values in the following format:
Name Amount
-----------------
Dside 75
Dside 125
Ex 75
Ex 125
Fin 75
Fin 125
Fin 80
I need to query the table and return the results in the following format:
Name Amount1 Amount2 Amount3
------------------------------
Dside 75 125
Ex 75 125
Fin 55 130 80
The amount could go on for 5 or 6 columns - it depends on what data is captured.
Can anybody help?
Here I have created some sample query to get the appropriate result. I integrate the EricZ solution. This query don't have limit for amount you can have n number of amount for Name.
SQL Fidde DEMO
Here is an example to display up to 6
[Amount]
as clouumns. If you have more than 6 Amount per [Name] or it's dynamic, you may look into this answer T-SQL dynamic pivotSQL Fidde DEMO