浅谈sql server把一个表中查询出来的数据插入到另外一个表中

时间:2025-03-09 20:53:52

1、

insert into A([id], ids, [name], type, time)

select [id], null, [name], 'dd', getdate() from B where type='dd'

2、

DECLARE @num int,@i int;
SET @i=0;
SET @num=(select 字段 from 表1 where 条件);
WHILE @i<@num
begin
set @i=@i+1;
insert INTO 表2(字段) SELECT 字段 from 表1 where 条件;
end;

3、

insert into b (column1,datecolumn)
select column1,getdate() from a