为什么说我的对象已存在?

Jackforid2003 2007-04-19 09:41:07
ALTER PROCEDURE [dbo].[testProc]
AS
BEGIN
declare @test int;
select count(*) as c into test from table2;
print @test

END

就定义了一个test变量,第一次执行存储过程的时候好的,第二次以后就不行了,说test变量已存在。。为什么?换了其他的变量名同样
我直到零时表可以drop table,变量怎么办哪?
...全文
114 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jackforid2003 2007-04-19
  • 打赏
  • 举报
回复
谢谢,正确,结贴
gahade 2007-04-19
  • 打赏
  • 举报
回复
语句写的也有问题
select count(*) as c into test from table2
这句是将结果存到test表中,但实际@test变量根本没接收到值
可以改成
ALTER PROCEDURE [dbo].[testProc]
AS
BEGIN
declare @test int;
select @test=count(*) from table2;
print @test

END
gahade 2007-04-19
  • 打赏
  • 举报
回复
ALTER PROCEDURE [dbo].[testProc]
AS
BEGIN
if exists(select 1 from sysobjects where xtype='U' and name='test')
drop table test
declare @test int;
select count(*) as c into test from table2;
print @test

END

34,590

社区成员

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

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