I have this long query that works but now I want to put it into a new table. When put into Test, in front of the from I'm getting these errors:Msg 156, Level 15, State 1, Line 17Incorrect syntax near the keyword 'into'.Msg 156, Level 15, State 1, Line 20Incorrect syntax near the keyword 'GROUP'.Msg 102, Level 15, State 1, Line 81Incorrect syntax near ')'.Their location is in bold below. What am I missing?Select b.doc, sum(b.pendinfo) as pendinfo, sum(b.pendover) as pendover,sum(pendndds) as pendndds,sum(pendndds300) as pendndds300,sum(pend250) as pend250, sum(pend300) as pend300,sum(pend350) as pend350, sum(pend399) as pend399,sum(pendinfo) + sum(pendndds) as Totpendfrom(SELECT t.doc, ISNULL(COUNT(distinct t.clm), 0)AS pendinfo, ISNULL(COUNT(distinct case when Datediff(DAY, t.app_rcpdt, Getdate()) > 300 then t.clm else null end), 0)AS pendover,CAST(NULL as int) AS pendndds,CAST(NULL as int) AS pendndds300,Isnull(COUNT(distinct case when Datediff(Day, t.app_rcpdt, Getdate()) > 249 and Datediff(Day, t.app_rcpdt, Getdate()) < 301 then t.cos else null end), 0) as pend250,Isnull(COUNT(distinct case when Datediff(Day, t.app_rcpdt, Getdate()) > 300 and Datediff(Day, t.app_rcpdt, Getdate()) < 351 then t.clm else null end), 0) as pend300,Isnull(COUNT(distinct case when Datediff(Day, t.app_rcpdt, Getdate()) > 350 and Datediff(Day, t.app_rcpdt, Getdate()) < 401 then t.clm else null end), 0) as pend350,ISNULL(COUNT(distinct case when Datediff(DAY, t.app_rcpdt, Getdate()) > 399 then t.clm else null end), 0)AS pend399into Test FROM t2dibpend t Where DIB_MVT_SEQ_NUM is NULL and t.cos not in (select cos from dbo.people where completedt is null) GROUP BY t.docunion allSELECT t.doc, Isnull(COUNT(distinct t.clm), 0) AS pendinfo, Isnull(COUNT(distinct case when Datediff(DAY, t.app_rcpdt, Getdate()) > 300 then t.clm else null end), 0) AS pendover,NULL,NULL,Isnull(COUNT(distinct case when Datediff(Day, app_rcpdt, Getdate()) > 249 and Datediff(Day, app_rcpdt, Getdate()) < 301 then t.clm else null end), 0) as pend250,Isnull(COUNT(distinct case when Datediff(Day, app_rcpdt, Getdate()) > 300 and Datediff(Day, app_rcpdt, Getdate()) < 351 then t.clm else null end), 0) as pend300,Isnull(COUNT(distinct case when Datediff(Day, app_rcpdt, Getdate()) > 350 and Datediff(Day, app_rcpdt, Getdate()) < 401 then t.clm else null end), 0) as pend350,ISNULL(COUNT(distinct case when Datediff(DAY, t.app_rcpdt, Getdate()) > 399 then t.clm else null end), 0)AS pend399into testfrom(select max(dib_mvt_seq_num) as dib_mvt_seq_num, clm From t2DibPend t group by clm)bleft join t2dibpend t on b.dib_mvt_seq_num=t.dib_mvt_seq_num and b.clm=t.clm where(DIB_MVT_TYP='r') and not (LOREC4 like 'R%' or LOREC4 like 'S%' or LOREC4 like 'V%' orLOREC4 like 'P%') and t.cos not in (select cos from dbo.people where completedt is null)group by t.doc union allSELECT t.doc, Isnull(COUNT(distinct t.clm), 0) AS pendinfo, Isnull(COUNT(distinct case when Datediff(DAY, t.app_rcpdt, Getdate()) > 300 then t.clm else null end), 0) AS pendover,NULL,NULL,Isnull(COUNT(distinct case when Datediff(Day, app_rcpdt, Getdate()) > 249 and Datediff(Day, app_rcpdt, Getdate()) < 301 then t.clm else null end), 0) as pend250,Isnull(COUNT(distinct case when Datediff(Day, app_rcpdt, Getdate()) > 300 and Datediff(Day, app_rcpdt, Getdate()) < 351 then t.clm else null end), 0) as pend300,Isnull(COUNT(distinct case when Datediff(Day, app_rcpdt, Getdate()) > 350 and Datediff(Day, app_rcpdt, Getdate()) < 401 then t.clm else null end), 0) as pend350,ISNULL(COUNT(distinct case when Datediff(DAY, t.app_rcpdt, Getdate()) > 399 then t.clm else null end), 0)AS pend399into testfrom(select max(dib_mvt_seq_num) as dib_mvt_seq_num, clm From t2DibPend t group by clm)cleft join t2dibpend t on c.dib_mvt_seq_num=t.dib_mvt_seq_num and c.clm=t.clm where (DIB_MVT_TYP='T') and t.cos not in (select cos from dbo.people where completedt is null)group by t.doc--WHERE (mvt_typ = 'R' or mvt_typ='T' ) and not (mvt_loc LIKE '[RSV]%')-- group by t.fo union all SELECT t.doc,NULL,NULL, Isnull(COUNT(distinct t.clm), 0) AS pendndds,ISNULL(COUNT(distinct case when Datediff(DAY, t.app_rcpdt, Getdate()) > 300 then t.clm else null end), 0)AS penddds300,Isnull(COUNT(distinct case when Datediff(Day, app_rcpdt, Getdate()) > 249 and Datediff(Day, app_rcpdt, Getdate()) < 301 then t.clm else null end), 0) as pend250,Isnull(COUNT(distinct case when Datediff(Day, app_rcpdt, Getdate()) > 300 and Datediff(Day, app_rcpdt, Getdate()) < 351 then t.clm else null end), 0) as pend300,Isnull(COUNT(distinct case when Datediff(Day, app_rcpdt, Getdate()) > 350 and Datediff(Day, app_rcpdt, Getdate()) < 401 then t.clm else null end), 0) as pend350,ISNULL(COUNT(distinct case when Datediff(DAY, t.app_rcpdt, Getdate()) > 399 then t.clm else null end), 0)AS pend399into testfrom(select max(dib_mvt_seq_num) as dib_mvt_seq_num, clm From t2DibPend t group by clm)dleft join t2dibpend t on d.dib_mvt_seq_num=t.dib_mvt_seq_num and d.clm=t.clm where(DIB_MVT_TYP='r') and (LOREC4 like '[RSV]%') and t.cos not in (select cos from dbo.people where completedt is null)group by t.doc)as bGroup By b.docorder by b.doc