DECLARE @Sample TABLE ( RentDate DATETIME );
INSERT INTO @Sample
VALUES ( GETDATE() ),
( GETDATE() - 1 ),
( GETDATE() - 2 ),
( '20150729 22:00:21.427' );
SELECT *
FROM @Sample S
WHERE S.RentDate > CAST(GETDATE() - 1 AS DATE)
AND S.RentDate < CAST(GETDATE() AS DATE);
select customernbr, storenbr, toolnbr, count(toolnbr)
from ToolsOnRent
where RentDate > cast((getdate()-1) as date)
and StoreNbr = '01101' and customernbr = '02001020'
group by CustomerNbr, storenbr, toolnbr
I don't see how using a cross apply adds value or makes it easier to maintain.
Open in new window