Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Replacing Nulls with text string Post Reply Post New Topic
Author Message
wawork
Newbie
Newbie
Avatar

Joined: 04 Feb 2008
Location: United States
Online Status: Offline
Posts: 3
Quote wawork Replybullet Topic: Replacing Nulls with text string
     Posted: 04 Feb 2008 at 1:48pm
First off I'm a Crystal Reports newbie trying to help another newbie.
 
We are running Crystal Reports 11 against views in a SQL Server 2000 database.  My user wants to display a text string whenever there are null values in a varible.  I've simplified the statement below but it still doesn't work.  All attempts, including the example relow, only result in the else condition working value being displayed in the report.
 
if isNull ({str24.strmname}) then
  "Stream not named in the database"
else
  "Not Missing";
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 04 Feb 2008 at 2:08pm
Take the semi-colon off the end of the formula.  You only need a semi-colon when there are multiple statements in a formula (if...then...else is one statment) and even then my experience has been that it works better if there is no semi-colon at the end.
 
-Dell
IP IP Logged
wawork
Newbie
Newbie
Avatar

Joined: 04 Feb 2008
Location: United States
Online Status: Offline
Posts: 3
Quote wawork Replybullet Posted: 04 Feb 2008 at 2:29pm
So I tried getting rid of the ; but nothing changed. 
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 04 Feb 2008 at 2:36pm
Ok, the data may not actually be null, it may be an empty string.  Try this:
 
if isNull({str24.strmname}) or ({str24.strmname} = "") then
  "Stream not named in the database"
else
  "Not Missing"
 
-Dell
IP IP Logged
wawork
Newbie
Newbie
Avatar

Joined: 04 Feb 2008
Location: United States
Online Status: Offline
Posts: 3
Quote wawork Replybullet Posted: 04 Feb 2008 at 3:59pm
Adding the ({str24.strmname} = "")   didn't help. :(
IP IP Logged
rvink
Groupie
Groupie
Avatar

Joined: 04 Feb 2008
Location: New Zealand
Online Status: Offline
Posts: 55
Quote rvink Replybullet Posted: 04 Feb 2008 at 4:08pm
In the formula where the code is defined, try changing the setting "Exceptions for Nulls" to "Default values for Nulls".

If you choose Exceptions For Nulls, the program treats a null value as an exception and halts formula evaluation when it encounters such a value.

If you choose Default Values For Nulls, the value that the program assigns varies depending on the data type that you are using in your formula. (These default values are the same values that are used for uninitialized variables.)


Another solution is to create an "SQL variable", they are created in a similar way to formulas. You would need something like this:

  IsNull("str24"."strmname", 'Stream not named in the database')

This code is put into the SQL query and is handled by the server, not Crystal. The IsNull function works different in SQL server from Crystal. In SQL server, if the field is Null it returns the value in the second parameter. Field and table names may be delimited in double quotes so strings must be delimited with single quotes. This method is more efficient since the SQL server does the work, not Crystal.


Edited by rvink - 04 Feb 2008 at 6:30pm
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