Home > front end >  where to put insert select statement?
where to put insert select statement?

Time:02-21

I have the following select statement and I want to input the results into my new table "additions" that I created. The select statement has the same columns in my new table

Select ThisWeek.* 
from
(
SELECT table1, table 2, table 3, getdate() as Date,
  FROM ...
  where ....)
  )ThisWeek
  left outer join
  (
  SELECT ...
  FROM .....
  where ..... ) LastWeek
  on .....
  where Lastweek... is null

  union

Select 
table1,table2
  getdate() as Date,
LastWeek.table1, lastweek.table2
(
SELECT...
  FROM ....
  ....
  FROM....)
  )ThisWeek
  Right outer join
  (
  SELECT table1, table 2 ....
  FROM ....
  where...
  FROM ....] ) - 2)
  ) LastWeek
  on ....
  where ... is null

CodePudding user response:

if you have created additions table use INSERT INTO

INSERT INTO additions (column1, column2, column3, ...)
Select ThisWeek.* 
from(
.....
)

you can use INTO syntax to create additions table as follows:

Select ThisWeek.* 
Into additions
from(
.....
)
  • Related