Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Analysis Server and Reporting Services (2005)
 Showing records between certain hours

Author  Topic 

xtrout
Starting Member

1 Post

Posted - 2007-06-19 : 14:58:50
Hello All,

I am trying to create a parameter that would show me the aggregated details of records happening within a certain time range on a given day. Some days the range of from hour - to hour changes. I can do it using CASE is the hours are the same each day but am having difficulty writing a statment the differs from day to day. Here is what i think it should look like...

((CASE WHEN Datepart(dw, TestDateTime) = 1 AND datepart(hh, TestDateTime) BETWEEN 0 AND 2 OR datepart(hh, TestDateTime) BETWEEN 8 AND 22 THEN 1 WHEN datepart(dw, TestDateTime) = 2 AND datepart(hour, TestDateTime) BETWEEN 6 AND 23 OR datepart(hour, TestDateTime) BETWEEN 23 AND 23 AND datepart(minute, TestDateTime) < 59 THEN 1 WHEN Datepart(dw, TestDateTime) BETWEEN 3 AND 7 AND datepart(hh, testDateTime) BETWEEN 6 AND 23 OR datepart(hh, TestDateTime) BETWEEN 23 AND 23 OR datepart(mi, TestDateTime) < 59 THEN 1 ELSE 0 END) >= @ShowCore)


Basically the core hours I am trying to show on the @ShowCore parameter is Sunday from Midnight to 2am and then 8am to 10pm, Monday from 6am to midnight(11:59) and then on Tuesday throught Saturday from Midnight to 2am and 6 am to 11:59.

I was hoping some could rewrite my code in correct syntax as I am have a rough time figuring it out.

Thanks much.
   

- Advertisement -