Solved

SQL Time Table

Posted on 2014-09-28
7
190 Views
Last Modified: 2014-09-28
I have a time table. I am trying to show every record in 15 minute intervals.

SELECT TimeID, CAST(Minute AS smallint) as IntMin, CAST(Second AS smallint) as IntSec, StandardTime from dim_Time

Open in new window

0
Comment
Question by:RecipeDan
[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
  • 3
  • 3
7 Comments
 
LVL 24

Expert Comment

by:Phillip Burton
ID: 40348828
And what's the Problem?
0
 
LVL 1

Author Comment

by:RecipeDan
ID: 40348865
I have data that looks like this:

TimeID	Time	Hour	MilitaryHour	Minute	Second	AmPm	StandardTime
1	00:00:00	00	00	00	00	AM	12:00:00 AM
2	00:00:01	00	00	00	01	AM	12:00:01 AM
3	00:00:02	00	00	00	02	AM	12:00:02 AM
4	00:00:03	00	00	00	03	AM	12:00:03 AM
5	00:00:04	00	00	00	04	AM	12:00:04 AM

Open in new window


I want to show all records with 15 minute intervals. So the data looks like this:

12:00
12:15
12:30
12:45
1:00
1:15 etc..
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40349112
use the Minute field

below I have used [n] but you would use [minute]

with cte as (
          select 0 as n union all
          select 14 union all
          select 15 union all
          select 24 union all
          select 30 union all
          select 44 union all
          select 45
          )
select
*
from CTE
where n % 15 = 0


|  N |
|----|
|  0 |
| 15 |
| 30 |
| 45 |
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 1

Author Comment

by:RecipeDan
ID: 40349171
That works but is not what I am looking for. I have a time table that lists all the times in a day from 12:00 am to 11:59 pm. What I want is a list of times that end in 15 minute intervals.

12:00
12;15
12:30
12:45
1:00
1:15
1:30
1:45 etc..
0
 
LVL 48

Accepted Solution

by:
PortletPaul earned 500 total points
ID: 40349189
This is how I though you might use the % 15:

select [time] from dim_time where [minute] % 15 = 0;

select [StandardTime]  from dim_time where [minute] % 15 = 0;
0
 
LVL 1

Author Comment

by:RecipeDan
ID: 40349240
You are correct. I misunderstood you. Thank you for your assistance. For reference here is the code, I decided to use military time.

SELECT MilitaryHour + ':' + CASE WHEN vartime = '0' THEN '00' ELSE vartime END AS vartime
FROM
(
select distinct MilitaryHour, CAST(inttime as varchar) as vartime
from
(
select cast(minute as smallint) as inttime, MilitaryHour from dim_time
)
t1
where inttime % 15 = 0
)
t2
order by vartime

Open in new window

0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40349244
I see.

thanks.

As this is a dimension table, does this imply there is substantial volume when you perform queries?

If this is true, and you have indexes on the string field called [minute]

Then you might be better off simply using an IN() like this:

SELECT
      MilitaryHour
FROM dim_time
WHERE [minute] IN ('00', '15', '30', '45')


sorry for the change of mind.
(Most dim tables I've used have used integers extensively, I had this in my mind. )
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
View SQL database for NPS accounting 4 25
mssql 7 32
What does "Between" mean? 6 48
SQL Server: Split string value in SELECT query only 5 30
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how the fundamental information of how to create a table.

710 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