Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

where to put insert select statement?

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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(
.....
)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading