用动态SQL:Create Procedure A(@p varchar)
as
declare @sql varchar(2000)
set @sql='select b from a where b='''+@p+''''
exec(@sql)
as
declare @sql varchar(2000)
set @sql='select b from a where b='''+@p+''''
exec(@sql)
as
select b from a where b=@p
(
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'
as
select b from a where b=@p
----------------------------------------
没道理呀,这也会错
是不是要对@P作一下处理,不过我不知道你是怎么传参数的,哈哈
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