0

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
Reporter
  • 3,897
  • 5
  • 33
  • 47

1 Answers1

1

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(
.....
)
RF1991
  • 2,037
  • 4
  • 8
  • 17
  • thanks, i have created additions table but when i put it before first select statement i get the following error: "String or binary data would be truncated. The statement has been terminated." –  Feb 21 '22 at 10:31
  • i cant add screenshot in these replies but in my first reply to your comment i have copied and pasted the error message –  Feb 21 '22 at 10:36
  • it is mainly due to length of string in design tab set data type of varchar to varchar(max) or nvarchar(max) – RF1991 Feb 21 '22 at 10:39
  • https://stackoverflow.com/questions/6388756/sql-server-string-or-binary-data-would-be-truncated – RF1991 Feb 21 '22 at 10:42
  • https://stackoverflow.com/questions/15019397/string-or-binary-data-would-be-truncated-the-statement-has-been-terminated – RF1991 Feb 21 '22 at 10:43