Data in SQL Server query time period

Source: Internet
Author: User
Tags sql server query rtrim

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.