SQL server入门:T-SQL编程
2008-09-04 10:00:38 来源:WEB开发网>[3] if-else 条件语句
if(条件)
begin
语句1
语句2
……
end
else
……
declare @myavg float
set @myavg = avg(writtenexam) from stumarks
print 平均分+convert(varchar(5),@myavg)
if(@myavg>70)
begin
print 本班笔试成绩优秀,前三名的成绩为:
select top 3 * form stumarks order by writtenexam desc
end
else
begin
print 本班笔试成绩较差,后三名的成绩为:
select top 3 * from stumarks order by writtenexam
end
……………………………………………………………………………………………………………………………………
>[4] while 循环语句
declare @n int
while(1=1)-----条件永远成立
begin
set @n = count(*) from stumarks where writtenexam<60
if(@n>0)
update stumarks set writtenexam = writtenexam+2
else
break
end
print 加分后的成绩为:
select * from stumarks
……………………………………………………………………………………………………………………………………
>[5] case 多分支语句
case
when 条件1 then 结果1
when 条件2 then 结果2
………
else
end
select * form stumarks
select stuno,成绩 = case
when writtenexam<60 then e
when writtenexam between 60 and 69 then d
when writtenexam between 70 and 79 then c
when writtenexam between 80 and 89 then b
else a
end
from stumarks
- ››sql server自动生成批量执行SQL脚本的批处理
- ››sql server 2008亿万数据性能优化
- ››SQL Server 2008清空数据库日志方法
- ››sqlserver安装和简单的使用
- ››SQL Sever 2008 R2 数据库管理
- ››SQL SERVER无法安装成功,sqlstp.log文件提示[未发...
- ››Sql Server中通过父记录查找出所有关联的子记录
- ››SqlServer触发器、存储过程和函数
- ››SQL Server 中的事务(含义,属性,管理)
- ››Sqlite数据库插入和读取图片数据
- ››Sql server 2005拒绝了对对象 'xx表' (数...
- ››Sql server 2005拒绝了对对象 'xx表' (数...
更多精彩
赞助商链接