zoukankan      html  css  js  c++  java
  • 临时表循环插入

    ALTER PROCEDURE [dbo].[Writelogin]
    AS
    BEGIN
    DROP TABLE #temp --删除临时表
    create table #temp --创建临时表
    (
      id int identity(1,1), --主键ID
      Name nvarchar(50),--司机
      Num nvarchar(50), --编号
      NextExamDate DATETIME, --行驶证下次年检
      DrivrQualificationLimitedDate DATETIME, --从业资格证
      NextDDTDate DATETIME,--DDT培训
      NextPhysicalCheckDate DATETIME, --FT培训
      NextTiredTrainDate DATETIME -- 体检
    )


    --声明字段
    declare @rows INT
    declare @n  int
    declare @driverName nvarchar(50)
    declare @driverNum nvarchar(50)
    declare @NextExamDate DATETIME
    declare @DrivrQualificationLimitedDate DATETIME
    declare @NextDDTDate DATETIME
    declare @NextPhysicalCheckDate DATETIME
    declare @NextTiredTrainDate DATETIME
    declare @ErrorMessage nvarchar(1000)
    select @n=1
    SET @ErrorMessage=''  --复制初始变量 否则 NULL+字符串=Null

    --插入符合条件的数据放到临时表
    insert #temp(NAME,Num,NextExamDate,DrivrQualificationLimitedDate,NextDDTDate,NextPhysicalCheckDate,NextTiredTrainDate) select NAME,Num,NextExamDate,DrivrQualificationLimitedDate,NextDDTDate,NextPhysicalCheckDate,NextTiredTrainDate
      FROM Driver WHERE  [Deleted]=0  AND (CONVERT(varchar(100), GETDATE(), 102)> NextExamDate
    OR CONVERT(varchar(100), GETDATE(), 102)> DrivrQualificationLimitedDate
    OR CONVERT(varchar(100), GETDATE(), 102)> NextDDTDate
    OR CONVERT(varchar(100), GETDATE(), 102)>NextPhysicalCheckDate
    OR CONVERT(varchar(100), GETDATE(), 102)>NextTiredTrainDate)

    select @rows = @@rowcount --查询表行数

    while @n <= @rows --是否大于表行数
    begin

    select @driverName=[Name],@driverNum=Num,@NextExamDate=NextExamDate,@DrivrQualificationLimitedDate=DrivrQualificationLimitedDate,@NextDDTDate=NextDDTDate,@NextPhysicalCheckDate=NextPhysicalCheckDate,@NextTiredTrainDate=NextTiredTrainDate FROM #temp WHERE id=@n

    IF(CONVERT(varchar(100), GETDATE(), 102)> @NextExamDate)
    BEGIN
      set @ErrorMessage += '行驶证下次年检日过期;';
    END

    IF(CONVERT(varchar(100), GETDATE(), 102)> @DrivrQualificationLimitedDate)
    BEGIN
     set @ErrorMessage +='从业资格证过期;';
    END

    IF(CONVERT(varchar(100), GETDATE(), 102)> @NextDDTDate)
    BEGIN
     set @ErrorMessage +='DDT培训过期;';
    END

    IF(CONVERT(varchar(100), GETDATE(), 102)> @NextPhysicalCheckDate)
    BEGIN
     set @ErrorMessage +='FT培训过期;';
    END

    IF(CONVERT(varchar(100), GETDATE(), 102)> @NextTiredTrainDate)
    BEGIN
     set @ErrorMessage += '司机体检过期;';
    END

    SET @ErrorMessage=@driverNum+'-'+@driverName+' '+@ErrorMessage;
    INSERT SysLogRecord(Cperator,IP,DEPT,[Content],YesOrNo,SystTme,LogType) values('System','','System',@ErrorMessage,1,getdate(),'系统处理');
    select @n = @n + 1

    end
    END

  • 相关阅读:
    jquery-4 完整表单验证实例
    从程序员的角度分析微信小程序(编程语言:用到什么学什么)
    微信程序开发
    css3-4 css3边框样式
    css3-3 css3背景样式
    boxfilter 实现
    opencv在arm和x86在移植
    PAT 1033. To Fill or Not to Fill (贪婪)
    [git] fatal: This operation must be run in a work tree
    spring与mybatis集成和事务控制
  • 原文地址:https://www.cnblogs.com/liuruitao/p/4950516.html
Copyright © 2011-2022 走看看