LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Replacing Null VALUES

    Employee
    Posted 01-26-2016 07:07

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: akash_123srm

    Hi guys I have run into a complex Situation I have a column named C1 with values as -

    C1:

    3
    3
    NULL
    NULL
    NULL
    2
    2
    2
    NULL
    NULL
    NULL

    I want all the NULLvalues to be replaced by the value just before NULL so the final Output should look like this:

    C1(original): C1(revised):
    3 3
    3 3
    NULL 3
    NULL 3
    NULL 3
    2 2
    2 2
    2 2
    NULL 2
    NULL 2
    NULL 2

    Any suggestions??


  • 2.  RE: Replacing Null VALUES

    Employee
    Posted 01-26-2016 07:42

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: stonysmith

    Add a filter with this code:

    if firstExec then C2 = null
    if C1.isNotNull() then C2=C1
    emit *
    emit C2
    In this code, C2 is only changed if the value of C1 is NOT null.
    But you've got to set an initial value for C2 or it doesn't work.


  • 3.  RE: Replacing Null VALUES

    Employee
    Posted 01-26-2016 08:02

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: akash_123srm

    Hi I tried the code and it works but would it be possible for you to explain the internal flow of the functions you have used.
    Why exactly do we Need the firstExec function.I excluded the first if condition & it worked as well. Thanks a lot for the code any ways. You are a saviour!!


  • 4.  RE: Replacing Null VALUES

    Employee
    Posted 01-27-2016 03:29

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: aop

    It does indeed work without providing initial value for C2 using firstExec but it might be considered a good practice. Your choice! The second if statement works simply by changing the value of the C2 variable only when C1 is not null. If C1 is null then current C2 value based on previous non-null C1 value is used.


  • 5.  RE: Replacing Null VALUES

    Employee
    Posted 01-27-2016 06:31

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: akash_123srm

    Thanks a lot for your explanation!!