sql - access 2007 add column using sub query -


i trying add 2 columns new table current query results. this: pic

in sql like:

select a.clm1
,a.clm2
,b.clm3
,(select udf_number newtable nt nt.udf_type_id=1 , nt.id=a.id) newcolumn1
,(select udf_number newtable nt nt.udf_type_id=2 , nt.id=a.id) newcolumn2
tablea inner join tableb b on a.id=b.id inner join newtable nt on nt.id=a.id

or using case like

select a.clm1
,a.clm2
,b.clm3
,(case when nt.udf_type_id=1 nt.udf_number) newcolumn1
,(case when nt.udf_type_id=2 nt.udf_number) newcolumn2
from..... ...

i tried few things in access, using sub queries in or part. didn't success. prb trying add 2 columns based on 1 column in new table. in getting done in access?

this valid access97 , above (i guess)

select a.clm1, a.clm2, b.clm3, nt1.udf_number newcolumn1, nt2.udf_number newcolumn2  tablea  inner join tableb b     on a.id=b.id  left  join newtable nt1 on nt1.id=a.id , nt1.udf_type_id = a.id - a.id + 1 left  join newtable nt2 on nt2.id=a.id , nt2.udf_type_id = a.id - a.id + 2 

please observe tricky part a.id - a.id + 1 needed access
other rdbms (or perhaps newer access versions) can be:

select a.clm1, a.clm2, b.clm3, nt1.udf_number newcolumn1, nt2.udf_number newcolumn2  tablea  inner join tableb b     on a.id=b.id  left  join newtable nt1 on nt1.id=a.id , nt1.udf_type_id = 1 left  join newtable nt2 on nt2.id=a.id , nt2.udf_type_id = 2 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -