2011-12-15 2 views
-1
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 [email protected] and 
        [email protected] and 
        itemcode=tbcoudet.itemcode 
      ) 
    group by memcode,expyear 
)'TurnOver' 
, * into #subodh from tbmember tbm where can_flag='N' 
end 
If @SubComCode= 0 
begin 
Insert into #subodh 
select 
(select sum(amount)  
    from tbcoudet 
    where memcode=tbm.memcode and expyear=(select max(expyear) from tbexpyear) 
    and exists(select itemcode 
      from tbitem 
      where [email protected] and 
        itemcode=tbcoudet.itemcode 
      ) 
    group by memcode,expyear 
)'TurnOver' 
, * from tbmember tbm where can_flag='N' 
end 

select top 10 * from #subodh where TurnOver is not null order by TurnOver desc 

end 

내 문제는 내가 그 다음 내가 오류에 geting EXEC sp_Member @comcode='1',@subcomcode='1' 또는 select top 10 * from #subodh where TurnOver is not null order by TurnOver이 쿼리를 실행하기 위하여려고 할 때이다 "잘못된 개체 이름 '#subodh'을." 제발 왜 내가이 오류가 geting 오전 및 어떻게 해결할 수 있습니다 ... 제발잘못된 개체 이름 '#subodh은'

답변

0

insert into 문으로 테이블을 만들 수 없기 때문에이 오류가 발생합니다. 이는 select일 수도 있고 일 수 없기 때문에 발생합니다. 그래서 컴파일러는 이후에 오류를 줄 수 있기 때문에이 코드를 허용하지 않습니다. 대신 insert into을 만드는

, createtable #subodh 첫 번째 (및 drop을 끝) 그리고 당신이 그 문제를받지 않습니다.

관련 문제