Link to home
Create AccountLog in
Avatar of JameMeck
JameMeckFlag for United States of America

asked on

MS SQL Mapping table.

I have 2 tables:
Table1:
Date
1
2
3
4
5

Table2:
Date       Section         Value
1              MAP              800
2              MAP              900
5              MAP              860

and I want to select them into 1 new Table3:
Date         Section         Value
1                  MAP           800
2                  MAP           900
3                  MAP             0
4                  MAP             0
5                  MAP           860

How can I do it with select statement?
Avatar of Nathan Riley
Nathan Riley
Flag of United States of America image

insert into table3
select date, section, value
from table 1 t1
inner join table2 t2 on t1.date = t2.date
one quick fix
insert into table3
select t1.date, section, value
from table 1 t1
inner join table2 t2 on t1.date = t2.date

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Raja Jegan R
Raja Jegan R
Flag of India image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of JameMeck

ASKER

Thanks! It is my final solution.