select * into #temp from Enterprise_Account where 1=2insert into #temp exec('select * from Enterprise_Account')
消息 213,级别 16,状态 7,第 1 行
列名或所提供值的数目与表定义不匹配。不要给我说列名不对,数目不对,是高手都知道不是这个问题。
经我反复测试,发现在 Enterprise_Account 表里的 ID设的是主键,如果去掉主键就好了,不知道原因如果改成 insert into #temp from Enterprise_Account 也可以执行通过。
现在的问题是结果集必须由存储返回,所以只能用这种写法,请大师指点!!!
消息 213,级别 16,状态 7,第 1 行
列名或所提供值的数目与表定义不匹配。不要给我说列名不对,数目不对,是高手都知道不是这个问题。
经我反复测试,发现在 Enterprise_Account 表里的 ID设的是主键,如果去掉主键就好了,不知道原因如果改成 insert into #temp from Enterprise_Account 也可以执行通过。
现在的问题是结果集必须由存储返回,所以只能用这种写法,请大师指点!!!
--这两句话是不一样的--这句是把Enterprise_Account 的内容插入到#temp中并创建表,因为1=2不成立,所以出现的是空表
select * into #temp from Enterprise_Account where 1=2--这句是插入到存在的#temp中,不会自动创建表
insert into #temp exec('select * from Enterprise_Account')
2.把'select * from Enterprise_Account'这句写在存储过程中.
create procedure my_proc
as
begin
select * from Enterprise_Account
end
goinsert into #temp exec my_proc
create table Enterprise_Account
(id int identity(1,1) primary key, col1 varchar(5), col2 varchar(5))insert into Enterprise_Account
select 'aa1','aa2' union all select 'bb1','bb2'select * from Enterprise_Accountid col1 col2
----------- ----- -----
1 aa1 aa2
2 bb1 bb2
-- 复制表结构
select * into #temp from Enterprise_Account where 1=2-- 导入数据时,排除id列: select col1,col2 from ..
insert into #temp exec('select col1,col2 from Enterprise_Account')select * from #tempid col1 col2
----------- ----- -----
1 aa1 aa2
2 bb1 bb2(2 row(s) affected)
as
begin
select * from enterprise_account
end
go
insert into #temp
exec my_proc