Pivoting question

  • 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

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • 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