表变量,临时表

2017-10-30 18:30:25来源:cnblogs.com作者:fight139人点击

分享
--表变量update invent set goodInfo=nulldeclare @tmp_goods table(    gno char(5))insert into @tmp_goods select gno from invent group by gnodeclare @gno char(6),@stno char(6),@gname varchar(255),@producer varchar(255)while exists(select gno from @tmp_goods)    begin        set rowcount 1        select @gno=gno from @tmp_goods        select @gname=gname,@producer=producer from goods where gno=@gno;        set rowcount 0        update invent set goodInfo=@gname+'-'+@producer where gno=@gno                delete from @tmp_goods where gno=@gno    endselect * from invent
--临时表  放在dbtemp数据库中if OBJECT_ID('tempdb.dbo.#tmp_inv','U') is not nulldrop table #tmp_invent方法1:create table #tmp_inv(id int)--方法2select * into #tmp_inv from invent

微信扫一扫

第七城市微信公众平台