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

  • 相关阅读:
    本来一行可以代替的树节点搜索
    mssql 重新开始标识
    TabContainer实现服务器端回传
    CSS中图片路径的问题
    Javascript在IE下设置innerHTML时出现"未知的运行时错误"
    sql union和union all的用法及效率
    关于动态添加TabPanel遇到的问题以及思考
    关于linq to sql调用存储过程,出现"无法枚举查询结果多次"的问题
    SQL Server 2005连接服务器时的26号错误解决!
    SQL 2000和2005 获取两表的差集
  • 原文地址:https://www.cnblogs.com/qizh/p/5695125.html
Copyright © 2011-2022 走看看