在写存储过程中报对象已经存在错误

benny7879 2007-03-13 11:42:22
代码如下
if @art2='7A'
begin
select bar9 as model,color as col,
sum(case when authority = 'TT' then quantity else 0 end ) as et_tt,
sum(case when authority = 'OH' and a.d_t > b.d_t_Last then quantity else 0 end ) as et_oh,
sum(case when authority = 'HO' and a.d_t > b.d_t_Last then quantity else 0 end) as et_ho,
sum(case when authority = 'SS' and a.d_t > b.d_t_Last then quantity else 0 end ) as et_ss
into #temp5s
from etamsellt a
inner join #TempTT b on a.shopno =b.shop_no and (a.d_t between b.d_t_Last and @date2)
where (bar9 like @art2 + '%') or bar9='7B8I02038' or bar9='7B8C18025' or bar9='7B7D18020' or bar9='7B8B18027' or bar9='7B0C08056' or bar9='7B0A08008' or bar9='7B0C08051'
group by a.bar9,a.color
end
else
begin
select bar9 as model,color as col,
sum(case when authority = 'TT' then quantity else 0 end ) as et_tt,
sum(case when authority = 'OH' and a.d_t > b.d_t_Last then quantity else 0 end ) as et_oh,
sum(case when authority = 'HO' and a.d_t > b.d_t_Last then quantity else 0 end) as et_ho,
sum(case when authority = 'SS' and a.d_t > b.d_t_Last then quantity else 0 end ) as et_ss
into #temp5s
from etamsellt a
inner join #TempTT b on a.shopno =b.shop_no and (a.d_t between b.d_t_Last and @date2)
where (bar9 like @art2 + '%')
group by a.bar9,a.color
end
这是个分支语句,但是在检查语法的时候报#temp5s已经存在,但是如果按照这个语句的意思应该只会创建一个@temp5s,应该不存在重复的可能。如果只留一个分支语句就通过了,不知哪位可以指点一下是怎么回事
...全文
193 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
baoshan 2007-03-13
  • 打赏
  • 举报
回复
在数据库中新建一个和#temp5s结构一样的表,然后用insert插入
tangqijun199 2007-03-13
  • 打赏
  • 举报
回复
你检查一下是不是循环执行了这个分支语句?
benny7879 2007-03-13
  • 打赏
  • 举报
回复
这个解决了,我后面一个用exec执行字符串,感谢大家交流
jacobsan 2007-03-13
  • 打赏
  • 举报
回复
看错,第一次用select ..into .. from..
第二次用insert into ..select...
OracleRoob 2007-03-13
  • 打赏
  • 举报
回复
先创建temp5s,再用insert into 追加到临时表中。
jacobsan 2007-03-13
  • 打赏
  • 举报
回复
if object_id('tempdb..#temp5s') is not null drop table #temp5s
jacobsan 2007-03-13
  • 打赏
  • 举报
回复
先在查询分析器中执行
drop table #temp5s
再保存该存储过程

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧