日期:2014-05-18  浏览次数:20465 次

带输入参数的存储过程怎么写???
建立一个存储过程,在运行这个存储过程的   时候需要输入一个参数值.那么这个存储过程该怎么写?   比如说一个需要参数才能运行循环的存储过程   能给个demo吗?       谢谢

------解决方案--------------------
if object_id( 'tbTest ') is not null
drop table tbTest
if object_id( 'spTest ') is not null
drop proc spTest
GO
----创建测试数据
create table tbTest(id int,name varchar(10))
insert tbTest
select 1, 'a ' union all
select 2, 'b ' union all
select 3, 'c '
GO
----创建带参数的存储过程.参数为要查询的表ID值
create proc spTest @id int
as
select * from tbTest where id = @id
GO
----执行存储过程
declare @id int
set @id = 2
EXEC spTest @id

----清除测试环境
drop table tbTest
drop proc spTest

/*结果
id name
----------- ----------
2 b
*/