Solved

Could you break this down for me?

Posted on 2016-10-03
5
38 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
  • 3
  • 2
5 Comments
 

Author Comment

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

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 46

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

937 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

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now