am/pm Query

Last Post 26 Dec 2008 06:35 AM by Headstrong. 1 Replies.
AddThis - Bookmarking and Sharing Button
Author Messages
Headstrong
New Member
New Member

--
24 Dec 2008 08:37 AM

I am using the query below to find records that the time is outside of the following range

before 5:45AM and after 6:15AM
before 5:15PM and after 5:45PM

I am doing something wrong

help!



SELECT * FROM dbo.Account INNER JOIN
dbo.Event_History ON dbo.Account.no = dbo.Event_History.no INNER JOIN
dbo.Event ON dbo.Event_History.cs_event_no = dbo.Event.event_no
WHERE (dbo.Event_History.[date] BETWEEN CONVERT(DATETIME, '2008-12-22 00:00:00', 102) AND CONVERT(DATETIME, '2008-12-23 00:00:00', 102)) AND
(CAST(CONVERT(nvarchar(8), dbo.Event_History.[date], 8) AS datetime) <= CAST('05:45' AS datetime) OR
CAST(CONVERT(nvarchar(8), dbo.Event_History.[date], 8) AS datetime) >= CAST('06:19' AS datetime)) AND (dbo.Event.descr LIKE '%O%') AND
(dbo.Account.name LIKE '%mikes%') AND (dbo.Account.no = '44123') OR
(dbo.Event_History.[date] BETWEEN CONVERT(DATETIME, '2008-12-22 00:00:00', 102) AND CONVERT(DATETIME, '2008-12-23 00:00:00', 102)) AND
(CAST(CONVERT(nvarchar(8), dbo.Event_History.[date], 8) AS datetime) <= CAST('17:15' AS datetime) OR
CAST(CONVERT(nvarchar(8), dbo.Event_History.[date], 8) AS datetime) >= CAST('17:45' AS datetime)) AND (dbo.Event.descr LIKE '%C%') AND
(dbo.Account.name LIKE '%mikes%') AND (dbo.Account.no = '44213')
ORDER BY dbo.Event_History.[date]
Headstrong
New Member
New Member

--
26 Dec 2008 06:35 AM
gunneyk,
you are da man!!!
you assumed correctly and solved my problem.
Also, thank you for the "Between" Tip

Thank Again!

Happy New year!


Acceptable Use Policy
---