What I need to do is a calculated column according to values returned by another field:
Supose:
declare @t TABLE (
code varchar(5),
address varchar(20),
result_type varchar(1),
result varchar(50)
)
insert into @t values ('0001', '', 'L', 'DFK-2020')
insert into @t values ('0001', '', 'F', 'code')
insert into @t values ('0001', '214, Samuel St', 'F', 'address')
What I need is a select statement returning:
DFK-2020
0001
214, Samuel St.
The only thing I can think of is:
select
case
when result_type = 'L' then result
when result_type = 'F' then (result) -- -> ?????
end as ret_values
I got lost in ????. I have to select a field according to what is stored in another field
Something like: "When 'result_type' is 'F', please select the value stored in a field which name is stored in 'result' "
in other languages/scenarios I used to achieve this with "macro references".Something like:
select &(result) from ...
How can I achieve that in sql server 2008 ?