77范文网 - 专业文章范例文档资料分享平台

SQL SERVER题库(4)

来源:网络收集 时间:2020-04-03 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

while @i<=99 【 3】

set @s=@s+@【4】 set @i=@i+【 5】 end print @s

[1B]declare[1E][2B]1[2E][3B]begin[3E][4B]i[4E][5B]2[5E] 7.计算2+4+6+……100空

【 1】 @i int,@s int set @s=0

set @i=【 2】 while @i<=100 【 3】

set @s=@s+@【4】 set @i=@i+【 5】 end

print @s [1B]declare[1E][2B]2[2E][3B]begin[3E][4B]i[4E][5B]2[5E] 7.求所有的3位正整数除以99的商和余数,并输出。

declare @i int, @a int, @b int set @i=【 1】 while @i<=【 2】 【 3】

set @a=@i【4】99 set @b=@i【 5】99 select @a , @b set @i=@i+1 end

[1B]100[1E][2B]999[2E][3B]begin[3E][4B]/[4E][5B]%[5E] 8.求1!+2!+3!+4!+5!。

declare @i int,@k int,@t int,@s bigint set @s=【 1】 set @k=1

while @k<=【 2】 begin

set @t=【 3】 set @i=1

while @i<=@【 4】 begin

set @t=@t*@i set @i=@i+1 end

set @s=@s+@【 5】 set @k=@k+1 end

print @s

[1B]0[1E][2B]5[2E][3B]1[3E][4B]k[4E][5B]t[5E] 9.统计未来100年中闰年的年份个数

declare @i int,@h int set @h=【 1】 set @i=2013

while @i<=【 2】 begin

if (@i%4=0 and @i0!=0) or (@i@0=0) set @h=@h+【 3】 set @i=@i+1 【4】

print @【 5】

[1B]0[1E][2B]2113[2E][3B]1[3E][4B]end[4E][5B]h[5E] 10.求1至100之间能被7整除的数之和

declare @i int,@s 【 1】 set @s=0

set @i=【 2】 while @i<=100 begin

if @i%【 3】=0 set @s=@s+@【 4】 set @i=@i+1 【 5】 print @s

[1B]int[1E][2B]1[2E][3B]7[3E][4B]i[4E][5B]end[5E] 11.求和:s=1+1/2+1/4++1/8……+1/1024 declare @i int,@s decimal(8,5)

set @s=【 1】 set @i=1

while @i<=【2】 begin

set @s=@s+1.0/【 3】(2,@i) set @i=@i+【4】 【 5】 print @s

[1B]1[1E][2B]10[2E][3B]power[3E][4B]1[4E][5B]end[5E] 12.求s=1+2+3+……+n>9999的最小n

declare @n int,@s int set @s=【1 】 set @n=1 b_1:

set @s=@s+@【2 】 set @n=@n+1

if @【3 】>=9999 begin

select @【4】 return end 【5】 b_1

[1B]0[1E][2B]n[2E][3B]s[3E][4B]n-1[4E][5B]goto[5E] 13.创建存储过程njc,求t=n!,并使用输出参数返回结果

Create 【1 】 njc

@i int,@n int, @t bigint 【2】 【3】

set @t=【4 】 set @i=1

while @i<=@n begin

set @t=@t*@【5 】 set @i=@i+1 end

[1B]procedure[1E][2B]output[2E][3B]as[3E][4B]1[4E][5B]i[5E] 14.求解方程ax2+bx+c=0 (a≠0) (建立过程:jfc)

【 1】 procedure jfc

@a float, @b float , @c float,

@x1 float output, @x2 float output , @xx varchar(30) output 【 2】 if @a=0 【3】

if @b*@b-4*@a*@c>=0 begin

set @x1=(-@b+sqrt(@b*@b-4*@a*@c))/(2*@a) set @x2=(-@b-sqrt(@b*@b-4*@a*@c))/(2*@a) select @x1,@【 4】 end 【5】

set @xx= ' 此方程无实根'

[1B]create[1E][2B]as[2E][3B]return[3E][4B]x2[4E][5B]else[5E] 五、程序题

1.求边长为10的正方形内切圆面积

declare @a int,@s float set @a=6

set @s=3.14*(@a/2)*(@a/2)

print '内切圆的面积为:'+cast(@s as varchar(10)) 2.已给2个正整数m=78和n=329,求n除以m的商和余数 declare @m int,@n int,@p int,@q int set @m=78 set @n=329 set @p=@n/@m set @q=@n%@m

select @p as 商,@q as 余数

3.任意给出两个变量a和b,编写程序实现两个变量a=5和b=9的值的交换. declare @a int,@b int,@t int set @a=5 set @b=9 set @t=@a set @a=@b set @b=@t

select @a a,@b

4.将任意一个3位正整数x=753进行分解,然后求其各个数位上的数字之和s declare @a int,@b int,@c int,@x int,@s int set @x=753

set @a=floor(@x/100)

set @b=floor((@x-@a*100)/10) set @c=@x-@a*100-@b*10 set @s=@a+@b+@c select @s

5. 若x='abc5hh73k9',求x中的数字之和 declare @a varchar(10),@s int set @s=0

set @a='abc5hh73k9'

set @s=@s+cast(substring(@a,4,1) as int) set @s=@s+cast(substring(@a,7,1) as int) set @s=@s+cast(substring(@a,8,1) as int) set @s=@s+cast(substring(@a,10,1) as int) print @s

6.已知三角形的三条边为a=7,b=9,c=5,求其面积. declare @a int,@b int,@c int,@p real,@s real set @a=7 set @b=9 set @c=5

set @p=(@a+@b+@c)/2

set @s=sqrt((@p-@a)*(@p-@b)*(@p-@c)*@p) print @s

7.求解一元二次方程:2x2+7x-78=0

declare @a int,@b int,@c int,@d real,@x1 real,@x2 real set @a=2 set @b=7 set @c=-78

set @d=@b*@b-4*@a*@c

set @x1=(-@b+sqrt(@d))/(2*@a) set @x2=(-@b-sqrt(@d))/(2*@a) print @x1 print @x2

8.判断某一年或今年是否为闰年.

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库SQL SERVER题库(4)在线全文阅读。

SQL SERVER题库(4).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/jiaoyu/929692.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: