zoukankan      html  css  js  c++  java
  • 游标练习

    USE [MHinfo]
    GO
    /****** Object: StoredProcedure [dbo].[U_AttMettingPerson] Script Date: 03/25/2015 23:46:33 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO

    ALTER proc [dbo].[U_AttMettingPerson]
    @id int
    as
    declare

    @UserName varchar(64),
    @UserID varchar(32),
    @DeptID char(4),
    @ArriveTime datetime ;

    begin
    declare ATT_Meeting_Peron_sursor cursor for

    Select A.MeetingID as MeetingID,
    D.UserName As UserName,
    C.UserID as UserID,
    D.DeptID as DeptID ,
    Convert(varchar(100),
    ( Select Top 1 AttDateTime
    From T_AttDataInfo
    Where CardNo = D.LogonID And AttDateTime >= DateAdd(Minute,-20,A.BeginDate) And AttDateTime <= DateAdd(Minute,20,A.BeginDate) ) ,120 ) As ArriveTime From T_Meeting A, T_MeetingAddress B, T_JoinMeetingPerson C, T_UserBaseInfo D Where A.MeetingAddressID = B.MeetingAddressID And A.MeetingID = C.MeetingID And C.UserID = D.UserID And A.MeetingID =@id

    open ATT_Meeting_Peron_sursor

    fetch next from ATT_Meeting_Peron_sursor into @id,@UserName ,@UserID,@DeptID,@ArriveTime;
    while @@FETCH_STATUS=0
    begin
    update T_JoinMeetingPerson set @ArriveTime=BeginDate=AA.ArriveTime from
    ( Select A.MeetingID,D.UserID, Convert(varchar(100), ( Select Top 1 AttDateTime From T_AttDataInfo Where CardNo = D.LogonID And AttDateTime >= DateAdd(Minute,-20,A.BeginDate) And AttDateTime <= DateAdd(Minute,20,A.BeginDate) ) ,120 ) As ArriveTime From T_Meeting A, T_MeetingAddress B, T_JoinMeetingPerson C,T_UserBaseInfo D Where A.MeetingAddressID = B.MeetingAddressID And A.MeetingID = C.MeetingID And C.UserID = D.UserID
    ) as AA
    where AA.MeetingID=T_JoinMeetingPerson.MeetingID and AA.UserID=T_JoinMeetingPerson.UserID and AA.MeetingID=@id ;

    fetch next from ATT_Meeting_Peron_sursor into @id,@UserName,@UserID,@DeptID,@ArriveTime;
    end;
    begin
    Select A.MeetingID as MeetingID, D.UserName As UserName,C.UserID as UserID,D.DeptID as DeptID , Convert(varchar(100), ( Select Top 1 AttDateTime From T_AttDataInfo Where CardNo = D.LogonID And AttDateTime >= DateAdd(Minute,-20,A.BeginDate) And AttDateTime <= DateAdd(Minute,20,A.BeginDate) ) ,120 ) As ArriveTime From T_Meeting A, T_MeetingAddress B, T_JoinMeetingPerson C, T_UserBaseInfo D Where A.MeetingAddressID = B.MeetingAddressID And A.MeetingID = C.MeetingID And C.UserID = D.UserID And A.MeetingID =@id;
    fetch next from ATT_Meeting_Peron_sursor into @id,@UserName ,@UserID,@DeptID,@ArriveTime;

    end ;
    close ATT_Meeting_Peron_sursor ;
    deallocate ATT_Meeting_Peron_sursor;
    end;

    转载 请注明原文地址并标明转载:http://www.cnblogs.com/laopo 商业用途请与我联系:lcfhn168@163.com
  • 相关阅读:
    用迭代法求x=a−−√。求平方根的迭代公式为 xn+1 = 12(xn + axn) 要求前后两次求出的x的差的绝对值小于10−5
    C 数组
    fofa自动化爬虫脚本更新+详解
    c# winfrom接收http协议body数据
    FLW要求
    modbus工具问题
    2020年总结
    WIFI K型热电偶传感器
    泛海三江烟感JTY-GD-H361 V2.7
    工位终端
  • 原文地址:https://www.cnblogs.com/laopo/p/4367415.html
Copyright © 2011-2022 走看看