Skip to content

How to get the range between dates in sql server

Mahesh Babu

Asked Aug 17, 2018, 1:05 AM EDTSolved
Share
LinkedInX
I Created one stored procedure 
 
 
Create Procedure [dbo].[GetEmployeesDates]
@StartDate as varchar(50),
@EndDate as varchar(50)
as
begin
SELECT *
FROM [ERS].[dbo].[employee] where Date>=@StartDate and date<@EndDate
 
now
 
if i pass the parameters i need get the date between range
 
and also i need to get the date without passing the parameters 
 
how can i do this one
 
please help me 
thanks 

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Rafnas T P
    ✓ Accepted answer0
    hi,
    try below code
     
    1. Create Procedure [dbo].[GetEmployeesDates]  
    2. @StartDate as varchar(50)=null,  
    3. @EndDate as varchar(50)=null  
    4. as  
    5. begin  
    6.   
    7. if @StartDate is not null and @EndDate is not null  
    8. begin  
    9. SELECT *  
    10. FROM [ERS].[dbo].[employee] where Date>=@StartDate and date<@EndDate  
    11. end  
    12. else  
    13. begin  
    14. SELECT *  
    15. FROM [ERS].[dbo].[employee]   
    16. end  
    17.   
    18. End  
     
    0
  • 1 short reply
    • 0
      thanks
      0