首页 > 代码库 > SQL Server 查询时间段内数据
SQL Server 查询时间段内数据
方式一:
ALTER Proc [dbo].[usp_Rpt_AcctTypeAudit]@FromDate datetime=null, -- yyyy-mm-dd (may change in the future!)@ToDate datetime=null, -- yyyy-mm-dd (may change in the future!)@UserID nvarchar(50) = ‘ALL‘asBEGIN set nocount on if @ToDate is not null begin set @ToDate=convert(varchar,@ToDate,112)+‘ 23:59:59:998‘ end select AcctType,AcctDesc,HostAcctType,AcctNumLength, case [Action] when ‘A‘ then ‘Add‘ when ‘D‘ then ‘Delete‘ when ‘M‘ then ‘Before-Modify‘ when ‘N‘ then ‘After-Modify‘ else ‘‘ end as [Action] ,UserID,WsID,CrtTime from AcctTypeMasterHist with(nolock) where (CrtTime >= @FromDate or @FromDate is null) and (CrtTime <= @ToDate or @ToDate is null) and (UserID = @UserID or @UserID=‘ALL‘ or isnull(@UserID,‘‘)=‘‘) order by crttime,LogIDEND
方式二:
create PROCEDURE [dbo].[Sp_CCBA_ProcessLogRpt] @FromDate datetime,@ToDate datetime,@UserID varchar(27),@Workstation varchar(28)ASSelect * from ProcessLogInfWHERE DATEDIFF(day, @FromDate, AcDate)>= 0 ANd DATEDIFF(day, AcDate, @ToDate)>= 0 AND LogUser = CASE RTRIM(@UserID) WHEN ‘ALL‘ THEN LogUser WHEN ‘‘ THEN LogUser ELSE @UserID END AND LogWs = CASE RTRIM(@Workstation) WHEN ‘ALL‘ THEN LogWs WHEN ‘‘ THEN LogWs ELSE @Workstation END
SQL Server 查询时间段内数据
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。