无效的对象名称#subodh“
问题描述:
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
我的问题是,当我要去执行EXEC sp_Member @comcode='1',@subcomcode='1'
OR select top 10 * from #subodh where TurnOver is not null order by TurnOver
这些查询的话,我歌厅错误“无效的对象名称#subodh'。”请告诉我为什么我geting这个错误,我该如何解决它...请无效的对象名称#subodh“
答
发生此错误,因为表可能不会创建与insert into
声明。发生这种情况是因为select
可能没有给出任何结果。所以编译器不允许这个代码,因为将来可能会给出错误。
而不是让一个insert into
的,create
的table #subodh
第一(和drop
它在结束),你不会得到这个问题。