首页 技术 正文
技术 2022年11月18日
0 收藏 382 点赞 4,797 浏览 1893 个字

1、while 循环

declare @ss int
set @ss=2
while @ss<10
begin
set @ss=@ss+1
print ‘HELLO’+convert(char(10),@ss)
if @ss=7
break
end

declare @sss int
set @sss=2
while @sss<10
begin
set @sss=@sss+1
if @sss=7
continue
print ‘HELLO’+convert(char(10),@sss)
end

–查询总分最高的学生的语文教师的所有信息
select*from teacher where tcode=
(select yujiao from student where xcode=
(select top 1 fcode from score group by fcode order by SUM(shufen+yufen+yingfen)desc))

2、存储过程

①    没有参数,没有返回值

–利用存储过程查找语文教师张晓华所教课程的学生的分数,
–过80的算优秀,优秀人数超过3个人即为【教师评测达标】
–若不到三个人,【不达标】
create proc x
as
declare @count decimal(18,2)
select @count=COUNT(*) from score where fcode
in(select xcode from student where yujiao=(select tcode from teacher where name=’邓凯’))and yufen>80
if @count>=3
print ‘教师测评达标’
else
print ‘不达标’
go
exec x–执行

② 有参数 ,没有返回值

–查看所输入编号的学生是否能够结业,两门以上及格即可结业
–三门都及格,【优秀】
–两门及格,【结业】
–一门及格,【不结业】
–三门都不及格,【请重修】
alter proc xinproc
@shu int
as
declare @shufen decimal(18,2),@yufen decimal(18,2),@yingfen decimal(18,2)
select @shufen=shufen,@yufen=yufen,@yingfen=yingfen from score where fcode=@shu
declare @sum int
set @sum=0
if @shufen>=60
set @sum+=1
if @yufen>=60
set @sum+=1
if @yingfen>=60
set @sum+=1
if @sum=3
print ‘优秀’
if @sum=2
print ‘及格’
if @sum=1
print ‘不及格’
if @sum=0
print ‘重修’
go
exec xinproc 2

③  有一个参数,有返回值

–输入一个学生的学号,想要经过存储过程之后得到在这个学生的总分

create proc firstproc1
@shu int
as
declare @sum decimal(18,2)
select @sum=SUM(shufen+yufen+yingfen)from score where fcode=@shu
return @sum
go
declare @fan decimal(18,2)
exec @fan=firstproc1 2 –定义一个变量接收
print @fan

④有两个参数,有返回值

create proc twelveproc
@one int,
@two int
as
declare @sum int
set @sum = @one +@two
return @sum
go
–执行
declare @fanhuizonghe int
exec @fanhuizonghe = twelveproc 2,4
print @fanhuizonghe

实例:

–存储过程练习:输入一个数,求1~n的和

alter proc sec
@n int
as
declare @sum int,@i int
set @sum=0
set @i=1
while @i<=@n
begin
set @sum=@sum+@i
set @i=@i+1
end
return @sum
go
declare @fan int
exec @fan=sec 4
print @fan

–存储过程练习:输入一个数求这个1!+2!+…+n!的阶乘

create proc m
@n int
as
declare @sum int,@jie int,@i int
set @sum=0
set @jie=1
set @i=1
while @i<=@n
begin
set @jie=@jie*@i
set @sum=@sum+@jie
set @i=@i+1
end
return @sum
go
declare @fan int
exec @fan=m 3
print @fan

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,954
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,479
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,291
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,108
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,740
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,774