Solved

Could you break this down for me?

Posted on 2016-10-03
5
34 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 45

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 45

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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

744 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

12 Experts available now in Live!

Get 1:1 Help Now