The last few weeks I've been working with Web based Reporting for SoftPro ProForm. It's been fun creating management review pages with dials and lights.
I've enjoyed combining multiple report outputs on one concise easy to ready web page. Along the way, it's been necessary to display SoftPro Database formatted date fields in a grid. They come through in 20130524 or "yyyyMMdd" format. It was easy enough to format that in a grid as "yyyy-MM-dd" format which worked until I started exporting the grids to Excel, when the formatting failed. So I began a search to fix it, at the SQL level.
There are a ton of examples of how to do this, they don't work for SoftPro Standard or Enterprise Databases, as when nothing is in the field, a "0" zero is stored, that caused a basic conversion to fail.
Out came the Case statement with a solution!
SELECT CASE WHEN Search.OrdDate = 0 THEN NULL
ELSE CAST(CAST(Search.OrdDate AS CHAR(8)) AS Date) END as OrderDate From Search
So we check the field to see if it's a zero, if so, send back a null to a column called OrderDate, if it's not a zero, cast or change the field from being an integer to a Date. This routine does a similar thing to the Crystal Reports Formula
Numbervar Year1:=Truncate( {DatesTimes.OrdDate} / 10000 );
Numbervar Month1:=Truncate(({DatesTimes.OrdDate}-(Year1*10000))/100);
Numbervar Day1:=Truncate({DatesTimes.OrdDate}-Truncate({DatesTimes.OrdDate}/100)*100);
Date(Year1,Month1,Day1);
I wonder if the same methodology would work in a Crystal Selection Formula, but since I started doing these Web based reports, I don't expect to live in Crystal for most reporting needs. This Live Report concept for SoftPro products is just awesome, we can export the grid to Excel with perfect formatting, add headers and footers if necessary, and it's all much faster than generating a Crystal Report. Most reports have been running in a few seconds, so in under a minute you can look at 8 or 10 different reports. Or just load up the Right Now page to see the aggregate numbers of selected reports in a dashboard style.
If you need to calculate the difference between dates, pull out the SQL command DATEDIFF(day, Date1CaseStatement, Date2CaseStatement) as DateDifferenceColumn.