PDA

View Full Version : مشکل در ایجاد جدول موقت



مرتضی حمزه ئی
شنبه 06 مهر 1387, 11:36 صبح
سلام دوستان عزیز
من داخل یک sp ابتدا دستور create table #temp (sanadno int ,sumprice bigint, sumkol bigint) رانوشتم وداخل sp رکوردهایی را از جای دیگه داخل این فایل موقت میریزم ولی موقعی که داخل vb این sp را صدا میزنم خطا میده ولی اگه خط اول مربوط به ایجاد جدول موقت را بردارم خطا نمیده جالبه در query analyzer اگه sp را صدا کنم مشکل نداره وجواب میده اگر لطف کنید مرا از برزخ نجات بدید ممنون میشم متن کامل sp بصورت زیر است
CREATE procedure spsanad1_fetch
@anbar int

as

declare @sumkol bigint
declare @sanadno int ,@sumprice bigint ,@descp nvarchar(30),@anbar1 int ,@period int
declare sumanbar_cursor cursor for
select * from vwacckalasanad where anbar=@anbar
union all
select * from vwaccbargsanad where anbar=@anbar and sanadnov>0
union all
select * from vwaccbargfrsanad where anbar=@anbar and sanadnov>0
union all
select * from vwacchavsanad where anbar=@anbar and sanadnov>0
union all
select * from vwaccresidsanad where anbar=@anbar and sanadnov>0
union all
select * from vwaccentgtosanad where anbard=@anbar and sanadnodv>0
union all
select * from vwaccentgfrsanad where anbarg=@anbar and sanadnogv>0
union all
select * from vwaccezafsanad where anbar=@anbar and sanadnov>0
order by period
open sumanbar_cursor
set @sumkol=0
fetch next from sumanbar_cursor
into @sanadno ,@sumprice ,@descp ,@anbar1 ,@period
while @@fetch_status=0
begin
if @period<5
begin
set @sumkol=@sumkol+@sumprice
end
else
set @sumkol=@sumkol-@sumprice
insert into #temp values(@descp,@sanadno,@sumprice,@sumkol)
fetch next from sumanbar_cursor
into @sanadno ,@sumprice ,@descp ,@anbar1 ,@period
end
select @sumkol
close sumanbar_cursor
deallocate sumanbar_cursor
-- select * from #temp
GO

mannai29
شنبه 06 مهر 1387, 12:01 عصر
به جای temp# بنویسید temp##.

کم حوصله
شنبه 06 مهر 1387, 15:27 عصر
سلام
اولا که جدول Table# کجا ساخته می شود یعنی در پروسیجری دیگر که راه حل همانی است که دوستمان گفت فقط فراموش نکنید که جداول دارای تک # بعد از اجرا ازبین می روند ولی جداول درارای دو شارپ ## را حتما باید از بین برد و ضمنا جدول تک # فقط توسط همان کاربر قابل دسترس است ولی آن یکی توسط تمام کاربران قابل دسترس است