trying to get date range to report

Posted on 2011-02-21
Last Modified: 2013-11-15
I am trying to get reports to print out according to dates - the issue is that it is not an absolute between this date and that date - it is a "is this report active during the dates given"
So the reports could start before the "date entered" the reports could end before the "date entered" but can never start before the end date and never end before the start date.
I have been working on this for 8 hours and am chasing myself in circles

Please see image -


WHERE ((cMinStart <= '''+ @start +''' AND cMinStart <= '''+ @end +''' AND cMaxEnd <= '''+@end+''' AND cMaxEnd >= '''+@start+''')
      OR (cMinStart <= '''+ @start +''' AND cMinStart <= '''+ @end +''' AND cMaxEnd >= '''+@start+''' OR cMaxEnd >= '''+@end+''' OR cMaxEnd <= '''+@end+''')
      OR (cMinStart <= '''+ @start +''' AND cMinStart <= '''+ @end +''' AND cMaxEnd >= '''+@start+''' AND cMaxEnd >= '''+@end+''')
      OR (cMinStart <= '''+ @start +''' AND cMinStart <= '''+ @end +''' AND cMaxEnd >= '''+@start+''' AND cMaxEnd <= '''+@end+''')
      OR (cMinStart  >= '''+ @start +''' AND cMaxEnd <= '''+@end+'''))
table information
these date line up as written in columns

An important message... (2/18/11)
An important message... (2/18/11)
Planned Service Interruption Notification (2/21/11
Ends but includes Today
flanky doodles
Starts and includes Today
This Month

2011-02-18 13:36:00.437
2011-02-21 08:52:17.537
2011-02-21 08:28:06.570
2011-02-21 14:22:38.700
2011-02-21 09:09:46.920
2011-02-18 00:00:00.000
2011-02-01 00:00:00.000
2011-02-21 00:00:00.000
2011-02-22 00:00:00.000

2040-01-01 00:00:00.000
2040-01-01 00:00:00.000
2040-01-01 00:00:00.000
2040-01-01 00:00:00.000
2040-01-01 00:00:00.000
2040-01-01 00:00:00.000
2011-03-01 00:00:00.000
2011-02-22 00:00:00.000
2040-01-01 00:00:00.000
Question by:tagomtech
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
LVL 41

Expert Comment

ID: 34947493
I did not see any image. Is the data provided, a sample from your table. Can you provide the table definition. Also post the expected result.

Author Comment

ID: 34951770
1. posting image!
2. yes the data is a sample but there are other things that are not needed that scripting it out would give.
clabael is a varchar
cminMax is a datetime (cast to a varchar in the stored procedure)
cminStart is a datetime (cast to a varchar in st proc)

If there is an easier way to do this I am all ears, my boss suggested using or and not
the results are seen in the pic - if there is a yes then that report should be pulled in when @start and @end are the same day - this is the time frame i am having trouble with.


Author Comment

ID: 34952290

table definition
CREATE TABLE [dbo].[DateTest_campaigns](
      [cLabel] [varchar](50) NOT NULL,
      [cMinStart] [datetime] NOT NULL,
      [cMaxEnd] [datetime] NOT NULL


data in file
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.


Author Comment

ID: 34953165
Corrected Data and result picture - REALLY need help with this
In the picture the rows highlighted in blue should not be included in a query returning todays dates -
Also uploading the correct datafile for the table so that the dates match what i am testing with

criteria for search
@start = '2011-02-22 00:00:00'
@end = '2011-02-22 23:59:59'


Author Comment

ID: 34953173
expected results - file returned without the blue highlights

Accepted Solution

tagomtech earned 0 total points
ID: 34953723

WHERE (((cMinStart <= '''+ @start +''' AND cMinStart !> '''+ @end +''' AND cMaxEnd > '''+@start+''') AND (cMaxEnd <= '''+@end+''' OR cMaxEnd >= '''+@start+'''))
      OR (cMinStart  >= '''+ @start +''' AND cMaxEnd <= '''+@end+'''))

Author Closing Comment

ID: 34990810
solved myself

Featured Post

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question