Solved

Could you break this down for me?

Posted on 2016-10-03
5
57 Views
Last Modified: 2016-10-03
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?"
0
Comment
Question by:brucegust
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:brucegust
ID: 41826541
Last part: 1950-01-01. Uncooperative fingers...
0
 
LVL 50

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 41826548
What's "1950-01-01?"
Means that if returned a NULL value it will be replaced by 1950-01-01.
0
 

Author Closing Comment

by:brucegust
ID: 41826555
Perfect!

Thanks!
0
 
LVL 50

Expert Comment

by:Vitor Montalvão
ID: 41826556
Anyway that test is not necessary since MAX() never returns NULL, so you can replace it with max(cast(statement.exportdate as date)).
0
 

Author Comment

by:brucegust
ID: 41826671
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question