I have a table like this in SQL:
Name Price
Ferrari White 1000
350z Purple 540
Lambo Black 2500
I'm wondering if there's a way to to create a temp table like this
Ferrari White 350z Purple Lambo Black
1000 540 2500
using a query.
Thanks in advance!
EDIT:
I'm using this code:
select Firstname, Amount, PostalCode, LastName, AccountNumber
from
(
select value, columnname
from yourtable
) d
pivot
(
max(value)
for columnname in (Firstname, Amount, PostalCode, LastName, AccountNumber)
) piv;
But the problem I have is that the name of the rows have spaces like this 'Ferrari White' so in the query I got error because it isn't a one word name.
EDIT2: (SOLVED)
I used this method:
select
max(case when columnname = 'FirstName' then value end) Firstname,
max(case when columnname = 'Amount' then value end) Amount,
max(case when columnname = 'PostalCode' then value end) PostalCode,
max(case when columnname = 'LastName' then value end) LastName,
max(case when columnname = 'AccountNumber' then value end) AccountNumber
from yourtable