dbomrrsm:
I tried the logic below and got the following error messages in Query Analyzer:
Server: Msg 170, Level 15, State 1, Procedure vw_Today_OR_Yesterday_2ndShift, Line 7
Line 7: Incorrect syntax near ','.
Server: Msg 156, Level 15, State 1, Procedure vw_Today_OR_Yesterday_2ndShift, Line 77
Incorrect syntax near the keyword 'END'.
***********************************************
Create View vw_Today_OR_Yesterday_2ndShift
AS
SELECT
CASE WHEN cast(datepart (hh, GetDate()) as Varchar(2)) >= 15 THEN
dt.StartDateTime,
dt.SystemDowntimeEndDateTime,
dt.DTCategoryID AS CatID,
Round((DATEDIFF(ss, dt.StartDateTime, dt.SystemDowntimeEndDateTime)/60.),2) AS Minutes,
dtdef.Name AS DTDefName,
(CASE WHEN cat.name is null THEN 'Not Acknowledged' ELSE cat.name END) As CatName
FROM
tblSystem
INNER JOIN tblDTDef as dtdef
INNER JOIN tblDowntime as dt
LEFT OUTER JOIN tblDTCategory as cat
ON (dt.DTCategoryID = cat.[ID])
ON (DTDef.[ID] = dt.DTDefID)
ON (tblSystem.[ID] = DTDef.SystemID)
WHERE
(dt.DTDefID = dtdef.ID) AND
(dt.SystemDowntime = 1) AND
(dtdef.SystemID = 2) AND
(dt.StartDateTime BETWEEN cast(datepart (mm, GetDate()) as Varchar(2))
+ '/' + cast(datepart (dd, GetDate()-1) as Varchar(2))
+ '/' + cast(datepart (yyyy, GetDate()) as Varchar(4))
+ ' 3:00:00 PM'AND
cast(datepart (mm, GetDate()) as Varchar(2))
+ '/' + cast(datepart (dd, GetDate()-1) as Varchar(2))
+ '/' + cast(datepart (yyyy, GetDate()) as Varchar(4))
+ ' 10:59:59 PM')
WHEN cast(datepart (hh, GetDate()) as Varchar(2)) < 15 THEN
SELECT
dt.StartDateTime,
dt.SystemDowntimeEndDateTime,
dt.DTCategoryID AS CatID,
Round((DATEDIFF(ss, dt.StartDateTime, dt.SystemDowntimeEndDateTime)/60.),2) AS Minutes,
dtdef.Name AS DTDefName,
(CASE WHEN cat.name is null THEN 'Not Acknowledged' ELSE cat.name END) As CatName
FROM
tblSystem
INNER JOIN tblDTDef as dtdef
INNER JOIN tblDowntime as dt
LEFT OUTER JOIN tblDTCategory as cat
ON (dt.DTCategoryID = cat.[ID])
ON (DTDef.[ID] = dt.DTDefID)
ON (tblSystem.[ID] = DTDef.SystemID)
WHERE
(dt.DTDefID = dtdef.ID) AND
(dt.SystemDowntime = 1) AND
(dtdef.SystemID = 2) AND
(dt.StartDateTime BETWEEN cast(datepart (mm, GetDate()) as Varchar(2))
+ '/' + cast(datepart (dd, GetDate()) as Varchar(2))
+ '/' + cast(datepart (yyyy, GetDate()) as Varchar(4))
+ ' 3:00:00 PM'AND
cast(datepart (mm, GetDate()) as Varchar(2))
+ '/' + cast(datepart (dd, GetDate()) as Varchar(2))
+ '/' + cast(datepart (yyyy, GetDate()) as Varchar(4))
+ ' 10:59:59 PM')
END
GO
**********************************************