在哪里放置 insert select 语句?
where to put insert select statement?
我有以下 select 语句,我想将结果输入到我创建的新 table“添加项”中。 select 语句在我的新 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
如果您已经创建了 additions table 使用 INSERT INTO
INSERT INTO additions (column1, column2, column3, ...)
Select ThisWeek.*
from(
.....
)
您可以使用 INTO 语法创建 additions table 如下:
Select ThisWeek.*
INTO additions
from(
.....
)
我有以下 select 语句,我想将结果输入到我创建的新 table“添加项”中。 select 语句在我的新 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
如果您已经创建了 additions table 使用 INSERT INTO
INSERT INTO additions (column1, column2, column3, ...)
Select ThisWeek.*
from(
.....
)
您可以使用 INTO 语法创建 additions table 如下:
Select ThisWeek.*
INTO additions
from(
.....
)