About the author

The author is just another obsessive compulsive hacker (the good kind) who when confronted with anything new can't help but wonder "how'd they do that?!?"

By day, I'm the Software Architect for CBMC; by night, I just try to "keep the clients happy" as Director of Technology for sdgInteractive.


MCPD

RSS Feed

Faking a null in Crystal Reports

by hilkiah 25. January 2007 07:01

I've been learning quite a bit about Crystal Reports in the last month. We've begin migrating all of the internal CBMC reporting tools from custom HTML display logic to using Crystal XI Developer. One of the more interesting issues I've run into resulted from trying to calculate a summary based on a formula. This basically took the following form: if (value = SOMEVALUE) then      include value or field My assumption was that the implied else clause would return null so that when I counted distinct values everyting not matching my filter would be ignored. However, it turns out that the implied else here does not return null - it returns the default value of the data type returned by the if statement, usually a blank string or 0. That, however, is a discrete value which gets counted as a unique occurrence causing the count in most circumstances to be 1 higher than expected. One would assume then that we just need to add an explicit else clause that returns null, right? Actually, Crystal doesn't have a constant or equivalent value to denote a null. Makes that a bit tough . . . After doing a little digging, however, I stumbled across an article from Ken Hamady that offered a workaround (or maybe hack is the right word) to deal with this. Essentially, you just create a formula field with a default value like an empty string or zero named @null. After saving and closing this field, re-open it and delete the value. Crystal will then view this formula as "null" and treat it appropriately in summaries. I'm not sure this an official solution, but it's been working for me so far using both the Crystal IDE and the ASP.NET crystal viewer.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

Web Development | Crystal Reports