Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table with the following structure

Period Name | Start Date | End Date
------------------------------------------
JAN | 01/01/2013 |31/01/2013
FEB | 01/02/2013 |28/02/2013
MAR | 01/03/2013 |31/03/2013


I want to search using a start date and end date. Ex: I want to know the periods between Jan 15 to Feb 15and I should get Jan and Feb. I tried the below using the below query but it is showing me all the records


Select * FROM FinancialPeriods WHERE (StartDate>='15/01/2014') Or (EndDate<='15/02/2014')


Appreciate your quick help


Thanks in advance

Sanaj
Posted
Comments
j snooze 6-May-14 18:03pm    
Try this(Sorry I did it in US datetime format instead of adding all the datetime converting.)

declare @startdate datetime,
@enddate datetime

select @startdate = '1/15/2013', @enddate = '2/15/2013'

Select * FROM FinancialPeriods
WHERE (@startdate between startDate and enddate)
or (@enddate between startDate and enddate)

1 solution

OR will returns records as long as they meet one of the conditions in the WHERE clause, try 'AND':
Select * FROM FinancialPeriods WHERE (StartDate>='15/01/2014') AND (EndDate<='15/02/2014')
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900