Luis Cazares (7/1/2015)
Steve,Just as an FYI, you can remove the ISNULL() by using the third parameter of LAG()
--Instead of
ISNULL(LAG(P.Lev, 1) OVER(PARTITION BY T.AccountID ORDER BY T.Datekey), 0) AS LAG_VALUE
-- Use
LAG(P.Lev, 1, 0) OVER(PARTITION BY T.AccountID ORDER BY T.Datekey) AS LAG_VALUE
Oh... I had read BOL on it, and I came away with the impression that it was the value of the 2nd parameter going NULL that would invoke the 3rd.
An interesting twist, and good to know. Thanks!
Steve (aka sgmunson) 🙂 🙂 🙂
Rent Servers for Income (picks and shovels strategy)