首页 > 其他 > 详细

存储过程

时间:2015-11-22 21:43:03      阅读:185      评论:0      收藏:0      [点我收藏+]

存储过程语法:

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!