22,210
社区成员
发帖
与我相关
我的任务
分享
SELECT a1=NULL,a2=NULL,* INTO #A FROM B
UPDATE #A SET a1='11',a2='ccc'
INSERT INTO #A(a1,a2) SELECT '22','adf'
create table tb
(
id int,
info varchar(10),
map int,
type varchar(10) not null
)
insert into tb
select 1,'a',2,'dd' union all
select 1,'b',2,'cc' union all
select 1,'c',2,'ccc' union all
select 2,'e',3,'cce' union all
select 2,'f',3,'ccf'
--解决方法
select id,info,map,type into #t from tb union all select null,null,null,null
delete from #t where id is null
insert into #t(id,info)
select 3,'222'
--插入成功
SELECT a1='11',a2='ccc'
,(b.col1 * 1) as col1 --数字
,cast(b.col2 as nvarchar(30)) as col2 --字符
,col3 -- 可空字段不必变换
,...
into #A
from B
INSERT INTO #A(a1,a2) SELECT '22','adf'