Click here to Skip to main content
15,895,859 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

i have three tables
1.line2
columns are
line_id, gate_id_fk, line_name, area_id, category(gate_id_fk is unique)

2. sheet 2
columns are
gate_id, category, area_id, area, year (same gate_id is unique)

3.line3
line_id, gate_id_fk, line_name, area_id, category, area(gate_id_fk is unique)


now i need to update line2 table and the columns which i need to update in line2 table are area_id, category from sheet2 table and line3 table

condition for those tables are

suppose
line2 (l2-Alias)
sheet2 B-Alias
line3 l3-Alias

1st where condition for data which is coming from
line3 l3 is

where L2.LINE_ID= L3.LINE_ID and L2.GATE_ID_FK is null)

and
2nd where condition for data which coming from sheet2 b

where L2.GATE_ID_FK= B.GATE_ID);


my question is how to update area_id, category columns in line2 table from both the tables together

Sql query or Stored proc plz.
Posted
Comments
Abhinav S 1-May-11 21:39pm    
Have you tried anything so far?

1 solution

You can achieve it in a following manner:

<br />
<br />
UPDATE              L2<br />
SET        L2.AreaID = S2.AreaID, <br />
           L2.Category = L3.Category<br />
FROM            Line2 L2<br />
INNER JOIN      Sheet2 S2 ON L2.gateID = S2.gateID<br />
INNER JOIN      Line3 L3 ON L3.gateID = S2.gateID<br />
<br />


Please let me know if you think that I am not understanding the question properly.

-Nayan
Coding is an earthly heaven
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900