zoukankan      html  css  js  c++  java
  • 存储过程的使用——循环,条件语句

    --while循环计算1到100的和 
    declare @a int
    declare @sum int
    set @a=1 
    set @sum=0 
    while @a<=100 
    begin
        set @sum+=@a 
        set @a+=1 
    end
    print @sum


    --if,else条件分支 
    if(1+1=2) 
    begin
        print ''
    end
    else
    begin
        print ''
    end
      
    --when then条件分支 
    declare @today int
    declare @week nvarchar(3) 
    set @today=3 
    set @week=case
        when @today=1 then '星期一'
        when @today=2 then '星期二'
        when @today=3 then '星期三'
        when @today=4 then '星期四'
        when @today=5 then '星期五'
        when @today=6 then '星期六'
        when @today=7 then '星期日'
        else '值错误'
    end
    print @week
  • 相关阅读:
    Set,List,Map的区别
    阅读笔记15
    阅读笔记14
    阅读笔记13
    阅读笔记12
    阅读笔记11
    阅读笔记10
    架构漫谈读后感
    阅读笔记1
    暑期周记8
  • 原文地址:https://www.cnblogs.com/yyl001/p/7073406.html
Copyright © 2011-2022 走看看