Frustratingly, I'm working with a table where the row name should be a value. How can I select that row in SQL Server based on a value? I'm aiming at something that looks like this:
;with QueryItems as
(
select year, model
from items
)
select ?QueryItems.model? as Price
from Pricing
where Year = QueryItems.year
Items table:
item year model
------------------------
xx 2001 MODELC
yy 2002 MODELA
zz 2002 MODELD
The pricing table is the weird one, set up as:
YEAR MODELA MODELB MODELC MODELD
------------------------------------------
2000 100 101 102 103
2001 205 206 250 300
2002 1000 1200 1500 1700
Results I'm aiming for:
item year model price
----------------------------
xx 2001 MODELC 250
yy 2002 MODELA 1000
zz 2002 MODELD 1700