Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 STORE PROCEDURE

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-08-23 : 19:55:23
ekachai writes "

CREATE PROCEDURE SP_GET_DETAIL_STOCK_IN2
@pid int,
@category nvarchar(3)
AS
create table #table(
stock_in_id int,
stock_name nvarchar(50),
iemi nvarchar(50),
detail nvarchar(50),
asset_price money,
last_date smalldatetime
)
if @category='mob'
begin
declare @stock_in_id int,
@stock_name_id int ,
@stock_name nvarchar(50),
@iemi nvarchar(50),
@detail nvarchar(50),
@asset_price money,
@last_date smalldatetime
declare mob_cursor cursor scroll for
select distinct a.stock_in_id from stock_in a
inner join stock_in_price b on a.stock_in_id=b.stock_in_id
where a.stock_product_id=@pid and a.hidden=0 and a.out=0
open mob_cursor
fetch next from mob_cursor into @stock_in_id
while @@FETCH_STATUS=0
begin
declare mob_cursor2 cursor scroll for
select top 1 a.stock_in_id,a.stock_name_id,a.iemi,a.detail,b.asset_price,b.stock_date from stock_in a inner join stock_in_price b on a.stock_in_id=b.stock_in_id
where a.stock_in_id=@stock_in_id order by b.stock_date desc
open mob_cursor2
fetch next from mob_cursor2 into @stock_in_id,@stock_name_id,@iemi,@detail,@asset_price,@last_date
while @@FETCH_STATUS=0
begin
select @stock_name=stock_name from stock_name where stock_name_id=@stock_name_id
insert into #table values(@stock_in_id,@stock_name,@iemi,@detail,@asset_price,@last_date)
fetch next from mob_cursor2 into @stock_in_id,@stock_name_id,@iemi,@detail,@asset_price,@last_date
end
close mob_cursor2
deallocate mob_cursor2
fetch next from mob_cursor into @stock_in_id
end
close mob_cursor
deallocate mob_cursor
select * from #table
end
else
select distinct a.stock_in_id,a.stock_name_id,a.detail,a.stock_qty,b.asset_price
from stock_in a inner join stock_in_price b on a.stock_in_id=b.stock_in_id
where a.stock_product_id=@pid and hidden=0 and out=0
GO

This store procedure is work in query analyzer tool but not work in
asp with command object .It error "Operation is not allowed when the object is closed. "
thank you"
   

- Advertisement -