S
slqbs-gy
Unregistered / Unconfirmed
GUEST, unregistred user!
我在SQL SERVER2000中写了这样一个SQL存储过程!<br>CREATE procedure memwinedetail<br> @d1 varchar(20),<br> @d2 varchar(20),<br> @mdcid varchar(20),<br> @cuid int<br>as<br>Create table #tmp(a1 varchar(20),a2 numeric,a3 numeric,a4 numeric,a5 varchar(50) Default('') )<br><br>Declare Cr_tmp cursor For <br> Select mdcid From memcard <br>Open Cr_tmp <br>Fetch Next From Cr_tmp into @mdcid <br>while (@@fetch_status = 0)<br>begin<br> select @cuid=isnull(max(cuid),0) from compartmentusedetail where Backchar2 like '%@mdcid%' and (cuddate between @d1 and @d2 ) and ifprint=1 <br> if @cuid!=0 begin<br> Insert into #tmp<br> select a.mdcid,a.othermoney3,a.othermoney4,a.jifen,'' from memcard as a where a.mdcid=@mdcid <br> union select a.clname,a.price,sum(a.num),sum(a.allprice),a.cudconsumekind from compartmentusedetail as a,memcard as b where b.mdcid=@mdcid and a.Backchar2 like '%@mdcid%' and (cuddate between @d1 and @d2 ) and ifprint=1 group by a.clid,a.clname,a.price,a.cudconsumekind <br> union select '消费总额' ,0,0,sum(allprice),'消费' from compartmentusedetail as a,memcard as b where b.mdcid=@mdcid and a.Backchar2 like '%@mdcid%' and cudconsumekind='消费'<br> end<br> Fetch Next From Cr_tmp into @mdcid<br>end<br>Close Cr_tmp<br>Deallocate Cr_tmp <br>GO <br>执行也是成功的,<br>当我在数据库中执行 exec memwinedetail '2000-10-10 8:00:00','2008-10-10 8:00:00','',0<br>提示也是成功的,按道理这时候数据库中应该有临时表 #tmp<br>可是当我执行 <br>select * from #tmp<br>却提示 #tmp 对象不存在!<br>很是不解,可能是因为哪个地方我做的不对,<br>请老鸟指教!