Alter Procedure sp_Member(
@comcode int = 0,
@SubComCode int = 0
)
as begin
set nocount on
If @comcode='0'
begin
select (
select sum(amount)
from tbcoudet
where memcode=tbm.memcode and
expyear=(select max(expyear) from tbexpyear)
and exists (
select itemcode
from tbitem
where comcode=@comcode and
SubComCode=@SubComCode and
itemcode=tbcoudet.itemcode
)
group by memcode,expyear
)'TurnOver', *
into #result from tbmember tbm where can_flag='N'
end
If @subcomcode='0'
begin
select (
select sum(amount)
from tbcoudet
where memcode=tbm.memcode and expyear=(select max(expyear) from tbexpyear)
and exists (
select itemcode
from tbitem
where comcode=@comcode and
itemcode=tbcoudet.itemcode
)
group by memcode,expyear
)'TurnOver', *
into #result from tbmember tbm where can_flag='N'
end
select top 10 * from #result where TurnOver is not null order by TurnOver desc
end
That is my sql code and when i am going to execute store procedure then I get the error
There is already an object named '#result' in the database.
Can anyone tell me what the problem is?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…