Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with Query

Status
Not open for further replies.

tek1ket

MIS
Jan 25, 2009
70
IR
I have a Table named Table1 with Following Record inside of it

Id FromBay FromPanel ToBay ToPanel
31 =A +B =C +D

and second Table named Table2
Id Table1Id Field1 Field2
2 31 Yes Yes
I want to have the Following result in a Query

PanelName Fiedl1 Field2
=A+B Yes Yes
=C+D null null

how can i write my SQL? I think i have problem with Fields in Table2? is yes how should change it
Thank you
 
I can see you want one line split into to with
FromBay and FromPanel on the first line
ToBay and ToPanel on the second line.

But how do you determine which of the two lines the values from Table2 match up with? Using ID of 31, it could match up with either line or both since they are all from ID 31 in table1.

-SQLBill

The following is part of my signature block and is only intended to be informational.
Posting advice: FAQ481-4875
 
with cte as (
select t1.Id, t1.FromBay, t1.FromPanel, t2.Field1, t2.Field2
from Table1 t1
join Table2 t2
on t1.id=t2.table1id
union all
Select t1.id, t1.ToBay, t1.ToPanel,'',''
from table1 t1
)
select *
from cte order by id

Simi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top