?
Solved

Could you break this down for me?

Posted on 2016-10-03
5
Medium Priority
?
63 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 51

Accepted Solution

by:
Vitor Montalvão earned 2000 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 51

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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
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.
Suggested Courses

771 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