Could you break this down for me?

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

What's "1950-01-012?"
brucegustPHP DeveloperAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

Vitor MontalvãoConnect With a Mentor MSSQL Senior EngineerCommented:
What's "1950-01-01?"
Means that if returned a NULL value it will be replaced by 1950-01-01.
brucegustPHP DeveloperAuthor Commented:
Last part: 1950-01-01. Uncooperative fingers...
brucegustPHP DeveloperAuthor Commented:

Vitor MontalvãoMSSQL Senior EngineerCommented:
Anyway that test is not necessary since MAX() never returns NULL, so you can replace it with max(cast(statement.exportdate as date)).
brucegustPHP DeveloperAuthor Commented:
All Courses

From novice to tech pro — start learning today.