有一个题目:在pubs数据库中创建一个存储过程,当操作者运行它并传递作者的姓后,返回所有关于这个作者的地址信息。
我写的存储过程是:
if exists(select name from sysobjects 
where name='mind' and type='p') 
drop proc mind
go
create procedure mind
@author_fname varchar(20)
as
select address from authors
where au_fname = '@author_fname'
go
大家帮忙看看哪里写错了??怎么我用语句exec mind Marjorie 调用这个存储过程时没想要的结果啊??

解决方案 »

  1.   

    select address from authors 
    where au_fname = @author_fname
      

  2.   

    你发错地方了,mssql的
    if exists(select name from sysobjects 
    where name='mind' and type='p') 
    drop proc mind 
    go 
    create procedure mind 
    @author_fname varchar(20) 
    as 
    begin
    set nocount on
    select address from authors 
    where au_fname = @author_fname
    set nocount off
    end
    go以上是返回结果集的形式,若你想做出输出参数调用的话,则在存储过程的参数列表加多一个输出参数,然后用select将对应数据赋给输出参数即可。
      

  3.   

    if exists(select name from sysobjects 
    where name='mind' and type='p') 
    drop proc mind 
    go 
    create procedure mind 
    @author_fname varchar(20) 
    as 
    select address from authors 
    where au_fname = '@author_fname' 
    go 
    这么写参数是传不进去的
      

  4.   


    if exists(select name from sysobjects 
    where name='mind' and type='p') 
    drop proc mind 
    go 
    create procedure mind 
    @author_fname varchar(20) 
    as 
    select address from authors 
    where au_fname = @author_fname 
    go