首页 > 数据库技术 > 详细

sqlserver 存储过程例子

时间:2015-06-18 20:20:58      阅读:279      评论:0      收藏:0      [点我收藏+]

//带参数的小列子

if (exists (select * from sys.objects where name = ‘proc_get_Purchasing2‘))

drop proc proc_get_student

go

alter proc proc_get_Purchasing2(@today int)

as

--declare @today int 

//申明变量

declare @weeks nvarchar(3) 

//设置变量值 set @weeks 

set @weeks=case

when @today = 1 then ‘星期一‘

when @today = 2 then ‘星期二‘

else ‘错误‘

end

print @weeks

    exec proc_get_Purchasing2  @today =2 



//带循环

if (exists (select * from sys.objects where name = ‘proc_get_Purchasing3‘))

drop proc proc_get_Purchasing3

go

create proc proc_get_Purchasing3

as

declare @sum1 int 

set @sum1=1

WHILE  @sum1<10

begin 

set @sum1 =@sum1+1

end


  exec proc_get_Purchasing3   



sqlserver 存储过程例子

原文:http://my.oschina.net/isxiaoge/blog/468483

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