[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

trying to get date range to report

Posted on 2011-02-21
7
Medium Priority
?
1,042 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 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

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!

Question has a verified solution.

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

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
What we learned in Webroot's webinar on multi-vector protection.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

834 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