Reputation: 2167
I want to get a Query to select some row from a table but I want to show the results not on rows but on column.
So for example:
SELECT V.IDPARAMETER AS ID, V.VALUE AS VALUE
FROM AA_V_RESULTS V
WHERE V.ID = ?
The result of this query is
ID VALUE
150 177
151 IN THE NORM
152 OK
Now I want that the result is this:
if(id = 150)
name of column is 'PARAMETER1'
else if(id = 151)
name of column is 'PARAMETER2'
else if(id = 152)
name of column is 'PARAMETER3'
So the result of the query is
PARAMETER1 PARAMETER2 PARAMETER3
177 IN THE NORM OK
It is possible to do this?
Upvotes: 0
Views: 36
Reputation: 11556
You can use a CASE
expression.
Query
select
max(case [ID] when 150 then [VALUE] end) as [Parameter1],
max(case [ID] when 151 then [VALUE] end) as [Parameter2],
max(case [ID] when 152 then [VALUE] end) as [Parameter3]
from [your_table_name];
Upvotes: 1