Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: SQL NULLIF to Crystal Syntax? Post Reply Post New Topic
Author Message
CR-Help
Newbie
Newbie


Joined: 29 Aug 2013
Online Status: Offline
Posts: 9
Quote CR-Help Replybullet Topic: SQL NULLIF to Crystal Syntax?
     Posted: 30 Aug 2013 at 3:52am
Hi I'm having some trouble. I'll give you an example of what I have in SQL

SQL:
distinct (count(NULLIF(field.column,0)))*100/distinct(count(field.column))

Basically have a table that has null and a range of 0-10 values. I need the 0 to be excluded from the count.

I have read, and read, and read and tried the suggestions that I had found using summaries and etc and had no success. I was hoping someone could shed more light into a successful way of accomplishing this in Crystal.

IS NULL is not the same as NULL IF.
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 30 Aug 2013 at 6:13am
Since you are using a command for crystal.  I think this will work (syntax may be incorrect).
count(case when field.column <> 0 then  1 else 0 end)
IP IP Logged
CR-Help
Newbie
Newbie


Joined: 29 Aug 2013
Online Status: Offline
Posts: 9
Quote CR-Help Replybullet Posted: 30 Aug 2013 at 6:18am
I need the 0 values to become null or to exclude them. This is because I need count to only count the rows with data with data values of 1-10.


Edited by CR-Help - 30 Aug 2013 at 6:19am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 30 Aug 2013 at 6:28am
you can use a running total with an evaluate formula
field<>0
or
you can use shared variable formulas to do the same as the Running Total


Edited by DBlank - 30 Aug 2013 at 6:28am
IP IP Logged
CR-Help
Newbie
Newbie


Joined: 29 Aug 2013
Online Status: Offline
Posts: 9
Quote CR-Help Replybullet Posted: 30 Aug 2013 at 7:07am
Already tried. I get 0 or 1.00 as my values. 
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 30 Aug 2013 at 7:14am
you are placing them in headers?
Running Totals only work in details and footers (like while printing records)
IP IP Logged
CR-Help
Newbie
Newbie


Joined: 29 Aug 2013
Online Status: Offline
Posts: 9
Quote CR-Help Replybullet Posted: 30 Aug 2013 at 8:06am
That's correct, I need it to display inside the headers.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 30 Aug 2013 at 8:23am

Can you change your source to use a command or sql stored proc or view so you can null out your values there?

Otherwise there are not a lot of alternatives from using a sub report to make the valeus appear in the headers.
IP IP Logged
CR-Help
Newbie
Newbie


Joined: 29 Aug 2013
Online Status: Offline
Posts: 9
Quote CR-Help Replybullet Posted: 30 Aug 2013 at 9:14am
I tried a stored proc but if I do the data becomes static and it won't change if I choose a different value in the parameters. Wouldn't that be an issue with the data becoming static because I used in SQL contained where clauses, and, and or operators.

here's quick ex:

select count(NULLIF(a,0))/count(b) from table a inner join table b
on a.field = b.field
left join table c on c.field1 = b.field1
left join table d on d.field = a.field
where a.field between 'daterangehere' and 'datarangehere'
and c.field1 = 'anydatastring'

that's just an example of what the query looks like



Edited by CR-Help - 30 Aug 2013 at 9:14am
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