CREATE PROCEDURE myproc
@lcs char(12) output
as
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=@lcsdelete 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
----**调用
declare @aa char(12)
myproc @aa output
select @aa
----------------------------------------

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=@lcsdelete 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=@lcsselect @lcs
commit;

解决方案 »

  1.   

    CREATE PROCEDURE myproc
    declare @aa  char(12) output
    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=@lcsdelete 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=@lcsset @aa=@lcs
    commit;