Select a specific column in SQL Server from a concatenation from a different table -


i'm trying select specific column based off value in table

i have 1 table following columns:

tablea:

item_id,column01,column02,column03,column04,column05,   

sample data tablea respectively:

1,$1.00,$2.00,$3.00,$4.00,$5.00 

tableb columns:

 item_id,column   

data tableb:

1,05 

i want able return value based on have in tableb. i'm concatenating field name, don't know how value.

select 'column'+tableb.[column]  tablea  inner join tableb on tablea.item_id = tableb.itemb tablea.item_id = 1 

so particular example query select column05 tablea , result $5.00.

you can use case statament

select case tableb.[column] when '01' tablea.column01                             when '02' tablea.column02                             when '03' tablea.column03                             when '04' tablea.column04                             when '05' tablea.column05        end value tablea  inner join tableb on tablea.item_id = tableb.itemb tablea.item_id = 1 

but column01 ... column05 of tablea need of same data type, or converted same data type.


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -