if else语句和if else嵌套
- 
      
 
 IF…ELSE语句
 
 
- 
      
 
 
 
 
- 
- 
        
 格式
 
- 
- 
          
 if boolean_expression
 
- 
          
 {sql_statement| statement_block}
 
- 
          
 else
 
- 
          
 {sql_statement| statement_block}
 
 
- 
          
- 
- 
        
 操作
 
- 
- 
          
 declare @num int——-声明
 
- 
          
 select @num = ———-查询
 
- 
          
 from 成绩——————查表
 
- 
          
 where 考试编号= ’01’ and 课程编号= ‘1’
 
 
- 
          
 
- 
        
- 
- 
- 
          
 if @num >80———if语句
 
 
- 
          
 
- 
- 
- 
- 
          
 begin
 
- 
- 
            
 print ‘这门课老师教的很成功’
 
 
- 
            
- 
          
 end
 
 
- 
          
 
- 
- 
- 
- 
          
 else
 
- 
- 
            
 print ‘这门课老师教的要努力’
 
 
- 
            
 
- 
          
 
- 
- 
      
 
 IF..ELSE语句嵌套
 
 
- 
- 
        
 操作
 
- 
- 
          
 declare @num int———-声明
 
- 
          
 select @num = AVG(分数)——-查询
 
- 
          
 from————–
 
- 
          
 where———
 
 
- 
          
 
- 
        
- 
- 
- 
          
 if
 
 
 @num >=60——————-if语句
 
 
- 
          
 
- 
- 
- 
- 
          
 
 begin
 
 
- 
- 
            
 
 if
 
 
 
 @num<70
 
- 
            
 print ”
 
- 
            
 
 else if
 
 
 
 @num<80———–嵌套
 
- 
            
 print”
 
- 
            
 
 else if
 
 
 
 @num<90
 
- 
            
 print ”
 
 
- 
            
- 
          
 
 end
 
 
 
- 
          
 
- 
- 
      
 
- 
- 
        
 
- 
- 
          
 
 else
 
 
 
- 
          
 
- 
        
- 
- 
- 
- 
            
 
 print‘需改进’
 
 
 
- 
            
 
- 
 
- 
 
