码迷,mamicode.com
首页 > 数据库 > 详细

sqlserver 存储过程例子

时间:2015-06-18 20:22:58      阅读:173      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!