Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Return a Null Value in a Formula Post Reply Post New Topic
Author Message
JennyB
Newbie
Newbie


Joined: 26 Dec 2012
Online Status: Offline
Posts: 24
Quote JennyB Replybullet Topic: Return a Null Value in a Formula
     Posted: 26 Dec 2012 at 11:00pm
Hi,

I've got a database field with dates of birth, these are stored as numbers in the format CYYMMDD and I want to convert them into date formats for my report. Because they're stored as numbers, records without DOBs have '0's in them, and I'd like to set the formula to return nulls where the field value in the DOB is 0, is this possible? Other than that I've got the date conversion working, its just this I'm stuck on.. :)

Thanks in advance!

Jenny
IP IP Logged
aharonmc
Newbie
Newbie


Joined: 02 Apr 2012
Location: United States
Online Status: Offline
Posts: 10
Quote aharonmc Replybullet Posted: 27 Dec 2012 at 5:33am
a null date is set as:
date(0,0,0)
IP IP Logged
shanth
Groupie
Groupie


Joined: 06 Aug 2012
Location: United States
Online Status: Offline
Posts: 75
Quote shanth Replybullet Posted: 27 Dec 2012 at 5:37am
I think it is possible. Create a Formula called NULL save it empty(without anything in it)
Modify your existing formula to:
If {DOB Field} = 0 or isnull{DOB Field} thenĀ  @NULL else
Your conversion formula(Date Format)
IP IP Logged
JennyB
Newbie
Newbie


Joined: 26 Dec 2012
Online Status: Offline
Posts: 24
Quote JennyB Replybullet Posted: 03 Jan 2013 at 2:32am
Hi,

Thank you for the replies, I can't get either solution to work, though that's probably me as I'm new to the formula editor. I'd really appreciate a few pointers. This is my date convertion formula, sourced with google :) :

NumberVar input := {Command.DOBI20};
if input = 0 then 010180 else
input:=input+19000000;
Date ( Val (ToText (input, 0 , "") [1 to 4]),
Val (ToText (input, 0 , "") [5 to 6]),
Val (ToText (input, 0 , "") [7 to 8]) )

It works fantastically, but for null dates (stored as 0 on the iSeries server) when I export my data to Excel these have been converted to 00/01/1900. I want the cell in Excel to be empty for these values.

I've tried to add in the empty formula called {@DateTest} with

NumberVar input := {Command.DOBI20};
input:=input+19000000;
if {Command.DOBI20} = 0 then {@DateTest} else
Date ( Val (ToText (input, 0 , "") [1 to 4]),
Val (ToText (input, 0 , "") [5 to 6]),
Val (ToText (input, 0 , "") [7 to 8]) )

But I get an error highlighting the Date(...) formula at the bottom saying 'A string is required here'.

I've tried the other solution as below, but it gives me exactly the same result as before, the 0 date values export into Excel as 00/01/1900.

NumberVar input := {Command.DOBI20};
input:=input+19000000;
if {Command.DOBI20} = 0 then Date(0,0,0) else
Date ( Val (ToText (input, 0 , "") [1 to 4]),
Val (ToText (input, 0 , "") [5 to 6]),
Val (ToText (input, 0 , "") [7 to 8]) )

Is it a fault in the formula as I've entered it or just that Crystal doesn't like null dates?

Thanks!

Jenny
IP IP Logged
JennyB
Newbie
Newbie


Joined: 26 Dec 2012
Online Status: Offline
Posts: 24
Quote JennyB Replybullet Posted: 03 Jan 2013 at 2:46am
Hooray, worked it out.. :) I've added Date(..) around the reference to the empty formula, so now the formula is below and it works, after exporting to Excel the cells are empty where DOBI20 is 0 in the database. Thank you! It would be nice if there was a way to do this in a single formula just for tidiness but at least its working now!

NumberVar input := {Command.DOBI20};
input:=input+19000000;
if {Command.DOBI20} = 0 then Date({@DateTest}) else
Date ( Val (ToText (input, 0 , "") [1 to 4]),
Val (ToText (input, 0 , "") [5 to 6]),
Val (ToText (input, 0 , "") [7 to 8]) )
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum