用动态SQL:Create Procedure A(@p varchar)
as
declare @sql varchar(2000)
set @sql='select b from a where b='''+@p+''''
exec(@sql)

解决方案 »

  1.   

    create proc T_A(@p varchar(10))
    as
    select b from a where b=@p
      

  2.   

    create table a
    (
       b varchar(10)
    )insert A select 'bb'create proc T_A(@p varchar(10))
    as
    select b from a where b=@pexec T_A 'bb'
      

  3.   

    Create Procedure A(@p varchar)
    as
    select b from a where b=@p
    ----------------------------------------
    没道理呀,这也会错
    是不是要对@P作一下处理,不过我不知道你是怎么传参数的,哈哈
      

  4.   

    Create Procedure A(@p varchar)
    as
    select b from a where b='bb'
    -----------------------------
    执行,有一条bb记录。
    --因为没有使用到参数但是换成:
    Create Procedure A(@p varchar)
    as
    select b from a where b=@p
    -----------------------------
    然后测试,将@p赋值 bb,但是没有记录。
    --这是因为参数@p没有说明长度,系统只取第一个字符,应该说明长度
    Create Procedure A(@p varchar(20))    --这样就能查询到
    as
    select b from a where b=@p
      

  5.   

    wangtiecheng(cappuccino)正解,在声明参数的数据类型时要指明其长度,否则系统默认都是1位长.