存储过程语法:
create procedure 存储过程名
@参数1名 数据类型[=默认值] [参数类型(输入/输出)]
......
@参数n名 数据类型[=默认值] [参数类型(输入/输出)]
as
SQL语句
go
--判断存储过程是否存在
if exists(select 1 from sys.sysobject where [name]=‘proc_GetPc‘)
drop procedure proc_GetPc --如果存在,删除存储过程
go
--创建不带参数的存储过程
create procedure proc_GetPc
--没有参数
as
select PCId as ‘电脑编号‘,
‘使用状态‘=case
where PCUse = 0 then ‘空闲‘
where PCUse = 1 then ‘使用‘
end,
PCNote as ‘备注‘ from PCInfo where PCUse = 0
go
--调用存储过程
exec proc_GetPc
--判断存储过程是否存在
if exists(select 1 from sys.sysobject where [name] = ‘proc_GetPcByParam‘)
drop procedure proc_GetPcByParam
go
--创建带输入参数的存储过程
create procedure proc_GetPcByParam
@PCUse int --输入参数,值表示电脑的使用状态
as
select PCId as ‘电脑编号‘,
‘使用状态‘ = case
where PCUse = 0 then ‘空闲‘
where PCUse = 1 then ‘使用‘
end,
PCNote as ‘备注‘ from PCInfo where PCUse = @PCUse
go
--调用存储过程,传人参数
exec proc_GetPcByParam 0
原文:http://www.cnblogs.com/709481260qq/p/4986620.html