zoukankan      html  css  js  c++  java
  • 分页存储过程+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

  • 相关阅读:
    字符编码
    各种数据类型内置方法
    数字类型内置方法一
    流程控制基础
    Python基础知识其三
    VirtualBox中使用ubuntu-16.04.1安装devstack的Compute节点
    VirtualBox中使用ubuntu-16.04.1安装devstack的Controller节点
    MySQL数据库简单操作
    MySQL常用命令及语句规范
    MySQL登录及退出
  • 原文地址:https://www.cnblogs.com/qizh/p/5695125.html
Copyright © 2011-2022 走看看