View Full Version : کار نکردن stored procedure بعد از upload
mohsen99
دوشنبه 18 مهر 1384, 11:24 صبح
با سلام
یک sp دارم مثلا به نام A
A داخل خودش sp به نام B را اجرا میکنه
B یک select انجام میده و نتیجه را داخل یک جدول موقت به نام temptable میریزه
A روی temptable باز select انجام میده
در آخر هم دستور drop table temptable اجرا میشه
این sp روی local بدون هیچ مشکلی اجرا میشه و کار میکنه
ولی بعد از upload در اولین بار اجرا پیغام میده که temptable وجود نداره
و در دومین بار اجرا sp B پیغام میده که temptable در دیتابیس موجوده و نمی تونه همچین جدولی بسازه
جالب اینه که وقتی متن sp A را داخل Query Analizer اجرا میکنم بدون مشکل اجرا میشه
به نظر شما اشکال از چی هست؟؟؟؟؟؟؟؟؟؟؟
titbasoft
دوشنبه 18 مهر 1384, 12:44 عصر
لطف کنید script اون رو بنویسید این طوری خیلی مشکل میشه نظر داد
Achchan
دوشنبه 18 مهر 1384, 18:19 عصر
ولی بعد از upload در اولین بار اجرا پیغام میده که temptable وجود نداره
You should create the temp table within same session that is executing sp A. Try this:
Go to QA and run this:
create table #t (id int)
go
insert into #t values (1)
go
select * from #t
go
Now open another session using Ctrl+N and submit this query:
select * from #t
go
you will got the following error:
Server: Msg 208, Level 16, State 1, Line 1
Invalid object name '#t'.
So you should create temp tables each time for use and at the end drop them.
و در دومین بار اجرا sp B پیغام میده که temptable در دیتابیس موجوده و نمی تونه همچین جدولی بسازه
I think this is clear: You can't create two temp tables with the same name within a single session.You should drop it and then re-create a new one.
By the way,requirements are a little strange for me: If you want just a select on another select's result why you don't do the proper select at first time? Or why you don't do a select on a view? Clarify me please.
Temp table concept is one of areas that I love Oracle for: no need to such a create ,drop and recreates.It is more intelligent!
-Best wishes and feel free to mail me: baronc_rampantc@yahoo.ca
mohsen99
دوشنبه 18 مهر 1384, 19:12 عصر
You should create the temp table within same session that is executing sp A. Try this:
temptable داخل sp B درست میشه و داخل sp A استفاده میشه
اگر session یکی نیست چرا local کار میکنه؟؟
If you want just a select on another select's result why you don't do the proper select at first time?
چون select اولی خودش روی چندین جدول و view انجام میشه و نتیجه آن باید برای چند sp دیگر استفاده بشه
CREATE PROCEDURE [dbo].A
@desid as int
AS
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
exec B @desid
select * from Complaint
where comno in (select ComNo from temptable)
drop table temptable
GO
CREATE PROCEDURE [dbo].B
@desid as int
AS
SELECT dbo.Complaint.ComNo into temptable
FROM dbo.ReferView INNER JOIN
dbo.Complaint ON dbo.ReferView.ComNo = dbo.Complaint.ComNo
WHERE (dbo.Complaint.Validation = 'T') AND (dbo.Complaint.Comit = 'F')
and (Download = '0') AND ([Update] = '1')
and destination=@desid
group by Complaint.ComNo
GO
titbasoft
دوشنبه 18 مهر 1384, 23:44 عصر
من هر چی دقت می کنم نمیتونم ببینم کجا temp table ساخته شده. در ضمن از local یا temp table ، global استفاده می کنید؟
برای کاری که شما می خواهید انجام بدید گاهی اوقات solution های بهتری همچون استفاده از user defined function وجود داره.
mohsen99
سه شنبه 19 مهر 1384, 15:13 عصر
من هر چی دقت می کنم نمیتونم ببینم کجا temp table ساخته شده
SELECT dbo.Complaint.ComNo into temptable
ممنون از توجهتون
خوشبختانه مشکل حل شد
مشکل از اینجا بود که روی کامپیوتر خودم user sa جدول ایجاد می کرد
اما رور سرور user mohsen
بنابر این هر جا که از temptable استفاده میشه باید mohsen.temptable نوشته بشه و نه dbo.temptable یا temptable تنها
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.