谁来帮助一下啊?

flowater1026 2002-12-16 12:01:12
select license as lcs
from MyWork..car
where model='Mazda' and license in(select license
from MyWork..owns
where ss =(select ss
from MyWork..person
where name='JohnSmith')
)

delete from MyWork..car
where license=lcs

delete from MyWork..accident
where aciddate =(select aciddate
from MyWork..acidlog
where license=lcs)
and driver =(select driver
from MyWork..acidlog
where license=lcs)

delete from MyWork..acidlog
where license=lcs

服务器: 消息 207,级别 16,状态 3,行 1
列名 'lcs' 无效。
服务器: 消息 207,级别 16,状态 1,行 13
列名 'lcs' 无效。
服务器: 消息 207,级别 16,状态 1,行 13
列名 'lcs' 无效。
服务器: 消息 207,级别 16,状态 1,行 21
列名 'lcs' 无效。

这该怎么改啊?
...全文
26 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
flowater1026 2002-12-16
  • 打赏
  • 举报
回复
CREATE PROCEDURE myproc
as
declare @lcs char(12)
select @lcs = license
from MyWork..car
where model='Mazda' and license in(select license
from MyWork..owns
where ss =(select ss
from MyWork..person
where name='JohnSmith')
)
delete from MyWork..car
where license=@lcs

delete from MyWork..accident
where aciddate =(select aciddate
from MyWork..acidlog
where license=@lcs)
and driver =(select driver
from MyWork..acidlog
where license=@lcs)

delete from MyWork..acidlog
where license=@lcs and driver='JohnSmith'

delete from MyWork..owns
where license=@lcs
commit;

服务器: 消息 2714,级别 16,状态 5,过程 myproc,行 28
数据库中已存在名为 'myproc' 的对象。

这个错误怎样改正啊?
archer_79 2002-12-16
  • 打赏
  • 举报
回复
CREATE PROCEDURE myproc
as
declare @lcs char(12)
select @lcs = license
from MyWork..car
where model='Mazda' and license in(select license
from MyWork..owns
where ss =(select ss
from MyWork..person
where name='JohnSmith')
)
delete from MyWork..car
where license=@lcs

delete from MyWork..accident
where aciddate =(select aciddate
from MyWork..acidlog
where license=@lcs)
and driver =(select driver
from MyWork..acidlog
where license=@lcs)

delete from MyWork..acidlog
where license=@lcs
commit;
archer_79 2002-12-16
  • 打赏
  • 举报
回复
下面三句SQL语句中的lcs用第一句SQL语句代替

在存储过程中用游标处理
xinyu_1980 2002-12-16
  • 打赏
  • 举报
回复
IF EXISTS (SELECT name
FROM sysobjects
WHERE name = 'myproc'
AND type = 'P')
DROP PROCEDURE myproc
GO
CREATE PROCEDURE myproc
as
declare @lcs char(12)
select @lcs = license
from MyWork..car
where model='Mazda' and license in(select license
from MyWork..owns
where ss =(select ss
from MyWork..person
where name='JohnSmith')
)
delete from MyWork..car
where license=@lcs

delete from MyWork..accident
where aciddate =(select aciddate
from MyWork..acidlog
where license=@lcs)
and driver =(select driver
from MyWork..acidlog
where license=@lcs)

delete from MyWork..acidlog
where license=@lcs and driver='JohnSmith'

delete from MyWork..owns
where license=@lcs
commit;
archer_79 2002-12-16
  • 打赏
  • 举报
回复
CREATE PROCEDURE (存储过程名称)
名字另取

34,590

社区成员

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

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