Solved

trying to get date range to report

Posted on 2011-02-21
7
1,033 Views
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

scenarios
Please see image -

query

SELECT *
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

clabel
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
Today
Tomorrow

cMinStart
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

cMaxStart
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
0
Comment
Question by:tagomtech
[X]
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
7 Comments
 
LVL 41

Expert Comment

by:Sharath
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.
0
 

Author Comment

by:tagomtech
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.



possiblescenarios.PNG
0
 

Author Comment

by:tagomtech
ID: 34952290

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

GO

data in file
campaigntestdata.csv
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:tagomtech
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'

campaigntestdata-correct.csv
0
 

Author Comment

by:tagomtech
ID: 34953173
expected results - file returned without the blue highlights
results.JPG
0
 

Accepted Solution

by:
tagomtech earned 0 total points
ID: 34953723
solution

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

Author Closing Comment

by:tagomtech
ID: 34990810
solved myself
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
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 and will be exposed to the many uses the SELECT statement has.

729 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