[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More
Experts Exchange Solution brought to you by
"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.
We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.
CREATE TABLE [dbo].[DimTime](
[TimeSK] [int] IDENTITY(1,1) NOT NULL,
[Time] [char](8) NOT NULL,
[Hour] [char](2) NOT NULL,
[MilitaryHour] [char](2) NOT NULL,
[Minute] [char](2) NOT NULL,
[Second] [char](2) NOT NULL,
[AmPm] [char](2) NOT NULL,
[StandardTime] [char](11) NULL,
CONSTRAINT [PK_DimTime] PRIMARY KEY CLUSTERED
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
SET ANSI_PADDING OFF
PRINT CONVERT(VARCHAR,GETDATE(),113)--USED FOR CHECKING RUN TIME.
--Load time data for every second of a day
DECLARE @Time DATETIME
SET @TIME = CONVERT(VARCHAR,'12:00:00 AM',108)
TRUNCATE TABLE DimTime
WHILE @TIME <= '11:59:59 PM'
INSERT INTO dbo.DimTime([Time], [Hour], [MilitaryHour], [Minute], [Second], [AmPm])
SELECT CONVERT(VARCHAR,@TIME,108) [Time]
WHEN DATEPART(HOUR,@Time) > 12 THEN DATEPART(HOUR,@Time) - 12
END AS [Hour]
, CAST(SUBSTRING(CONVERT(VARCHAR,@TIME,108),1,2) AS INT) [MilitaryHour]
, DATEPART(MINUTE,@Time) [Minute]
, DATEPART(SECOND,@Time) [Second]
WHEN DATEPART(HOUR,@Time) >= 12 THEN 'PM'
END AS [AmPm]
SELECT @TIME = DATEADD(second,1,@Time)
SET [HOUR] = '0' + [HOUR]
WHERE LEN([HOUR]) = 1
SET [MINUTE] = '0' + [MINUTE]
WHERE LEN([MINUTE]) = 1
SET [SECOND] = '0' + [SECOND]
WHERE LEN([SECOND]) = 1
SET [MilitaryHour] = '0' + [MilitaryHour]
WHERE LEN([MilitaryHour]) = 1
SET StandardTime = [Hour] + ':' + [Minute] + ':' + [Second] + ' ' + AmPm
WHERE StandardTime is null
AND HOUR <> '00'
SET StandardTime = '12' + ':' + [Minute] + ':' + [Second] + ' ' + AmPm
WHERE [HOUR] = '00'
Open in new window
SELECT TOP (24) RIGHT('00'+CAST(ROW_NUMBER() OVER (ORDER BY object_id)-1 AS VARCHAR(2)),2)+':00'
+ '-' + RIGHT('00'+CAST(ROW_NUMBER() OVER (ORDER BY object_id)-1 AS VARCHAR(2)),2)+':59' AS Band
Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.