Here's the line of code I want to understand:
coalesce(max(cast(statement.exportdate as date)),'1950-01-01')
One piece at a time, here we go:
Coalesce: returns the first value that isn't NULL.
Max: Here, I'm getting the most recent date in the recordset
Cast: converts whatever data you're looking at to a specific data type. In this instance, it's a timestamp and I'm converting it to a date