Solved

trying to get date range to report

Posted on 2011-02-21
7
1,027 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
  • 6
7 Comments
 
LVL 40

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now