Way One:
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( -)= ' All' asBEGIN SetNocount on if @ToDate is not NULL begin Set @ToDate=Convert(varchar,@ToDate, the)+'23:59:59:998' End SelectAccttype,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 fromAccttypemasterhist 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 byCrttime,logidEND
Way two:
Create PROCEDURE [dbo].[sp_ccba_processlogrpt] @FromDate datetime,@ToDate datetime,@UserID varchar( -),@Workstation varchar( -) asSelect * fromProcessloginfWHERE DATEDIFF( Day,@FromDate, acdate)>= 0 and DATEDIFF( Day, Acdate,@ToDate)>= 0 andLogUser= Case RTRIM(@UserID) when ' All' ThenLogUser when "' ThenLogUserELSE @UserID END andLogws= Case RTRIM(@Workstation) when ' All' ThenLogws when "' ThenLogwsELSE @Workstation END
Data in SQL Server query time period