July 1, 2015 at 10:43 am
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
July 1, 2015 at 11:29 am
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)
Viewing 2 posts - 16 through 16 (of 16 total)
You must be logged in to reply to this topic. Login to reply