Okey , Since you have not specified exact table structure and data so I have considered below
Table1
(A BIGINT ,
B NVARCHAR(50) ,
C NVARCHAR(50) ,
D NVARCHAR(50) ,
E NVARCHAR(50)
)
Table2
(F NVARCHAR(50) ,
G NVARCHAR(50) ,
H NVARCHAR(50) ,
B NVARCHAR(50) ,
K BIGINT
)
Table1 |
---|
A | B | C | D | E |
---|
10 | B1 | C1 | D1 | E1 |
20 | B2 | C2 | D2 | E2 |
Table2 |
---|
F | G | H | B | K |
---|
F1 | G1 | H1 | B1 | 10 |
F1 | G2 | H2 | B2 | 20 |
And here is the sql proc as per your need
CREATE TABLE #table1 (B NVARCHAR(10),SumOfA BIGINT,C NVARCHAR(50),D NVARCHAR(50),E NVARCHAR(50))
CREATE TABLE #table2 (B NVARCHAR(10),SumOfK BIGINT,F NVARCHAR(50),G NVARCHAR(50),H NVARCHAR(50))
INSERT INTO #table1
SELECT B,SUM(A),C,D,E FROM Table1 GROUP BY B,C,D,E
INSERT INTO #table2
SELECT B,SUM(K),F,G,H FROM Table2 GROUP BY B,F,G,H
SELECT B,SumOfA,SumOfK,C,D,E,F,G,H FROM #table1 T1 Inner Join #table2 T2 On T1.A=T2.A
Hope this helps , If yes then plz accept and vote the answer. Any queries / questions on this are always welcome.
Thanks & Regards
RDBurmon.Sr.Software Engineer