CASE statement if else Magic ETL


Hey guys I am trying to fill a column based on certain criteria from 4 columns.

I think it would be best to do this in another column so that I'm not overwriting anything. 

My table looks like the following and I'm trying a Case Statement that fills in the null spaces, but I think my case statement is missing something or I'm missing a step. 



My case statement looks like this so far:

CASE when `date_created`=`date_updated` and `time_created`=`time_updated` and `publish_date` IS NULL then `date_created` else `publish_date` end

Unfortunately my case statement sucks and this doesn't work to my advantage. 


Can anyone help?


  • GrantSmith

    Hi @user052846 

    You didn't clearly state what exactly your issue was with your beast mode so I'm somewhat guessing here but you're essentially wanting to use the most recent date between publish date and update date  for the publish date if the publish date is null correct?


    If that's correct then you have two independent conditions dependent upon each other. Essentially you're saying the dates must be the same and publish date must be null in order for you to use the creation date.  I'm assuming here too that your creation date and updated date will be the same when an entry is created. With those assumptions you can just narrow down your beast mode to using the updated date if the publish date is null.


    Simplifies down to:

    IFNULL(`publish_date`, `date_updated`)



    **Was this post helpful? Click Agree or Like below**
    **Did this solve your problem? Accept it as a solution!**
  • jaeW_at_Onyx

    a series of nested IFNULL statements will get the job done as per Grant's recommendation, but have a look at COALESCE() it will return the first non null value in a chain.


    if you want to write it as a case statement then do a series of null checks



    when colA is not null then colA

    when colB is not null then colB

    when colC is not null then colC


    else ...



    by definition you don't need to build extensive logic b/c in order for the second clause (test for B) to apply, colA must have been null (otherwise the preceeding logic step would have applied).

    Jae Wilson
    Check out my 🎥 Domo Training YouTube Channel 👨‍💻

    **Say "Thanks" by clicking the ❤️ in the post that helped you.
    **Please mark the post that solves your problem by clicking on "Accept as Solution"