• 分页存储过程+int转换字符串+时间格式转换


    USE [AAA]
    GO

    /****** Object: StoredProcedure [dbo].[RPT_FK_Visitors] Script Date: 07/22/2016 14:12:10 ******/
    SET ANSI_NULLS ON
    GO

    SET QUOTED_IDENTIFIER ON
    GO

    ALTER PROC [dbo].[BBB]
    @pIndex int --页号
    ,@pPage int --页行数
    ,@dateTimeStart varchar(20)--开始时间
    ,@dateTimeEnd varchar(20)--结束时间
    ,@visitorName varchar(100)
    ,@no varchar(30) 
    ,@vPhone varchar(20) 
    as
    begin
    SELECT * INTO #tmp
    FROM(
    SELECT '0' AS ID,'正在' AS Name
    UNION
    SELECT '1' AS ID,'离开' AS Name
    UNION
    SELECT '2' AS ID,'预约' AS Name
    UNION
    SELECT '3' AS ID,'取消预约' AS Name
    UNION
    SELECT '4' AS ID,'其他' AS Name) A

    declare @userName varchar(100)
    set @userName='%'+ @visitorName +'%'

    declare @credentialsNo varchar(30)
    set @credentialsNo='%'+ @no +'%'

    declare @vistorPhone varchar(20)
    set @vistorPhone='%'+ @vPhone +'%'
    --记录总数
    SELECT intCount=Count(*) from T_FK_Visitor where VisitTime between
    @dateTimeStart and @dateTimeEnd
    and Name like @userName
    and CredentialsNo like @credentialsNo
    and Phone like @vistorPhone

    if(@pPage=0)
    begin
    select v.VisitorNumber,
    v.Name,
    v.Sex,
    v.CredentialsType,
    v.CredentialsNo,
    v.Phone,
    v.Company,
    v.Address,
    v.VCardID,
    v.VCause,
    v.Belongings,
    v.CarInfo,
    v.VisitorSum,
    CONVERT(varchar(100),VisitTime,120)as VisitTime,
    CONVERT(varchar(100),LeaveTime,120)as LeaveTime,
    t.Name as VisitStateID
    from T_FK_Visitor v,#tmp t
    where v.VisitTime between @dateTimeStart and @dateTimeEnd
    and v.Name like @userName
    and v.CredentialsNo like @credentialsNo
    and Phone like @vistorPhone
    and t.ID = v.VisitStateID
    end
    else
    begin
    declare @MID int
    set @MID=(@pIndex-1)*@pPage
    ;with T as (select row_number() over(order by VisitTime) as VisitorID,
    v.VisitorNumber,
    v.Name,
    v.Sex,
    v.CredentialsType,
    v.CredentialsNo,
    v.Phone,
    v.Company,
    v.Address,
    v.VCardID,
    v.VCause,
    v.Belongings,
    v.CarInfo,
    v.VisitorSum,
    v.VisitTime,
    v.LeaveTime,
    v.VisitStateID
    from T_FK_Visitor v
    where v.VisitTime between @dateTimeStart and @dateTimeEnd
    and v.Name like @userName
    and v.CredentialsNo like @credentialsNo
    and Phone like @vistorPhone)

    select Top(@pPage)VisitorNumber,t.Name,t.Sex,t.CredentialsType,t.CredentialsNo,t.Phone,t.Company,t.Address
    ,t.VCardID,t.VCause,t.Belongings,t.CarInfo,t.VisitorSum
    ,CONVERT(varchar(100),t.VisitTime,120)as VisitTime
    ,CONVERT(varchar(100),t.LeaveTime,120)as LeaveTime
    ,tmp.Name as VisitStateID
    from T t,#tmp tmp
    where VisitorID> @MID
    and t.VisitStateID = tmp.ID
    end
    end


    GO

  • 相关阅读:
    基于动态IP的Internet视频监控解决方案(作者:吴晓晖)
    Avid
    Silverlight 自定义控件的继承问题
    VOD三种VOD视频点播技术的简介和比较
    服务器主流存储:SAS存储知识问答
    获取oracle系统数据的sql
    C#去除字符串空格的几种方法
    利用Windows Media实现IP组播
    两种宽带接入方式HFC与ADSL的比较
    C#中用XMLDocument写文件时,去掉XMLNS属性
  • 原文地址:https://www.cnblogs.com/qizh/p/5695125.html
Copyright © 2020-2023  润新知