• sql 存储过程里的if else while


    一:if  else 

       语法: if 条件 begin 执行的操作 end else begin 执行的操作 end

    二:while

      语法:while 条件 begin 执行操作 end

    实例:

    USE [OABusiness]
    GO
    /****** 对象:  StoredProcedure [dbo].[inertdate]    脚本日期: 08/31/2012 15:30:23 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE procedure [dbo].[inertdate]
    (
         @date  datetime , --插入的日期
         @flag  int --判定插入的数据
    )
    AS
    begin
    declare @count int;--用户记录条数
    set @count=null;
    declare @count_add int ;--计数
    set @count_add=1;
    declare @Userid int ;--用户Userid
    set @Userid =NUll;
    declare @WorkHour int ;--插入的时间
    declare @SignStatus int ;--状态
    end
    if @flag=0
    begin
    set @WorkHour=0
    set @SignStatus=1
    end 
    else if @flag=1
    begin
    set @WorkHour=28800
    set @SignStatus=0
    end
    begin
    --获取记录条数
    select @count=count(*) from dbo.T_UserInfo where Away_YN !=1
    --循环插入记录
    while @count_add<@count+1 
    begin
    select @Userid=UserID from 
    ( select row_number() over(order by UserID asc) as num,UserID,Away_YN from dbo.T_UserInfo where Away_YN !=1) as tem 
    where num=@count_add
    
    insert into dbo.T_SigninStatistics (UserID,SignDate,WorkHour,SignStatus) values(@Userid,@date,@WorkHour,@SignStatus)
    set @count_add=@count_add+1 
    end
    end
  • 相关阅读:
    (译)linux系统关于命令echo的15个例子
    linux之grep实例讲解
    linux grep练习
    (译)"usermod"命令使用完全指导---15个练习例程截图
    linux分区,文件系统,目录结构概述
    Linux 配置YUM
    Linux 强制安装rpm 包
    $LANG、$NLS_LANG 记录一下
    Oracle性能诊断艺术-相关脚本说明
    datafile相关(add、rename、drop)
  • 原文地址:https://www.cnblogs.com/fuge/p/2667507.html
Copyright © 2020-2023  润新知