我想用一个table类型的变量储存一个select查询的结果,怎么做? 注意,是用变量,不是用select into newtable===>表变量,必须手工创建,不能由select * into @tb from tb 语句得到, 正确写法是: declare @tb table (col varchar(10),....) insert into @tb select * from tb
create table #t(id int, name varchar(100))insert into #t(id, name) select 1,'aaa' union all select 2,'bbb' union all select 3,'ccc' union all select 4,'ddd'select * from #tdeclare @tp table (id int, name varchar(100))insert into @tp select * from #tselect * from @tpdrop table #t
insert into @t select 1,2
insert into @t select 2,3
id varchar(80)
)insert @t select p_msg_id from inbox
--定义表变量
declare @t table(id int,columns varchar(10))
--操作就和普通表操作一样.它驻留在内存中。
注意,是用变量,不是用select into newtable===>表变量,必须手工创建,不能由select * into @tb from tb 语句得到,
正确写法是:
declare @tb table (col varchar(10),....)
insert into @tb
select * from tb
select 1,'aaa' union all
select 2,'bbb' union all
select 3,'ccc' union all
select 4,'ddd'select * from #tdeclare @tp table (id int, name varchar(100))insert into @tp
select *
from #tselect * from @tpdrop table #t