M
Mitchell_Collen via AccessMonster.com
Hi, I am new to access and can't figure this one out. Does anyone know how to
do this? Here is my code:
ps: this function is not requiring parameters at this time. Thanks. MC
________________________________
ALTER FUNCTION CountOrders
()
RETURNS TABLE
AS
RETURN ( SELECT count(dbo.phmOrderState.EnteredBy) AS entered, count(dbo.
phmOrderState.ReviewedBy) AS reviewed, count(dbo.phmOrderState.OrderStateTime)
As Total,
'Shift' = CASE WHEN DATEPART(hh, dbo.phmOrderState.
OrderStateTime)
BETWEEN '07' AND '14' AND DATEPART(mi, dbo.
phmOrderState.OrderStateTime) BETWEEN '0' AND '59' THEN 'shift 1' WHEN
DATEPART(hh,
dbo.phmOrderState.OrderStateTime) BETWEEN '15' AND '22'
AND DATEPART(mi, dbo.phmOrderState.OrderStateTime) BETWEEN '0' AND
'59' THEN 'shift 2' WHEN DATEPART(hh, dbo.phmOrderState.
OrderStateTime) BETWEEN '23' AND '24' OR
DATEPART(hh, dbo.phmOrderState.OrderStateTime) BETWEEN
'0' AND '6' AND DATEPART(mi, dbo.phmOrderState.OrderStateTime) BETWEEN '0'
AND
'59' THEN 'shift 3' END
FROM dbo.phmOrderState INNER JOIN
dbo.phmOrderNumber ON dbo.phmOrderState.Visit# = dbo.
phmOrderNumber.Visit# AND
dbo.phmOrderState.Orderkey = dbo.phmOrderNumber.
OrderKey AND
dbo.phmOrderState.OrderStateTime = dbo.phmOrderNumber.
OrderStateTime LEFT OUTER JOIN
dbo.phmCombinedProduct ON dbo.phmOrderState.Visit# =
dbo.phmCombinedProduct.Visit#
Group By 'Shift' ) -- <------------------------ I am not sure how to
reference the case statement in the select statement
____________________________________
do this? Here is my code:
ps: this function is not requiring parameters at this time. Thanks. MC
________________________________
ALTER FUNCTION CountOrders
()
RETURNS TABLE
AS
RETURN ( SELECT count(dbo.phmOrderState.EnteredBy) AS entered, count(dbo.
phmOrderState.ReviewedBy) AS reviewed, count(dbo.phmOrderState.OrderStateTime)
As Total,
'Shift' = CASE WHEN DATEPART(hh, dbo.phmOrderState.
OrderStateTime)
BETWEEN '07' AND '14' AND DATEPART(mi, dbo.
phmOrderState.OrderStateTime) BETWEEN '0' AND '59' THEN 'shift 1' WHEN
DATEPART(hh,
dbo.phmOrderState.OrderStateTime) BETWEEN '15' AND '22'
AND DATEPART(mi, dbo.phmOrderState.OrderStateTime) BETWEEN '0' AND
'59' THEN 'shift 2' WHEN DATEPART(hh, dbo.phmOrderState.
OrderStateTime) BETWEEN '23' AND '24' OR
DATEPART(hh, dbo.phmOrderState.OrderStateTime) BETWEEN
'0' AND '6' AND DATEPART(mi, dbo.phmOrderState.OrderStateTime) BETWEEN '0'
AND
'59' THEN 'shift 3' END
FROM dbo.phmOrderState INNER JOIN
dbo.phmOrderNumber ON dbo.phmOrderState.Visit# = dbo.
phmOrderNumber.Visit# AND
dbo.phmOrderState.Orderkey = dbo.phmOrderNumber.
OrderKey AND
dbo.phmOrderState.OrderStateTime = dbo.phmOrderNumber.
OrderStateTime LEFT OUTER JOIN
dbo.phmCombinedProduct ON dbo.phmOrderState.Visit# =
dbo.phmCombinedProduct.Visit#
Group By 'Shift' ) -- <------------------------ I am not sure how to
reference the case statement in the select statement
____________________________________