Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: SQL Expression Issue in CR 8.5 Post Reply Post New Topic
Author Message
josh2009
Newbie
Newbie


Joined: 26 Jun 2009
Location: United States
Online Status: Offline
Posts: 16
Quote josh2009 Replybullet Topic: SQL Expression Issue in CR 8.5
     Posted: 17 Feb 2010 at 9:03am
Using an older Crystal Reports version and trying to insert a SQL expression which works in SQL Server Mgmt Studio but getting a syntax error in Crystal. Below is my SQL -
 
SELECT Sum(Cath_ACC.PCIProcedure)
FROM Demographics INNER JOIN Event_Cath ON Demographics.SS_Patient_ID = Event_Cath.SS_Patient_ID INNER JOIN Cath_Procedures  ON Event_Cath.SS_Event_Cath_ID = Cath_Procedures.SS_Event_Cath_ID  INNER JOIN Cath_ACC    ON Event_Cath.SS_Event_Cath_ID = Cath_ACC.SS_Event_Cath_ID  INNER JOIN SS_Selection_Set_Elements_BLGH  ON Cath_Procedures.Procedure_Name = SS_Selection_Set_Elements_BLGH.Element_Text 
WHERE SS_Selection_Set_Elements_BLGH.ACC_Field = 'Y'
    AND (Event_Cath.Order_Number NOT LIKE 'IR%' or Event_Cath.Order_number is null)
 AND (Cath_ACC.PCIProcedure = 1 or Cath_ACC.ProcedureDiagnostic = 1)   
 AND Event_Cath.Date_of_Cath > '20100101'
Group By Demographics.Patient_ID, Demographics.Last_Name, Demographics.First_Name,
    Event_Cath.Order_Number, Event_Cath.Date_of_Cath
ORDER BY Demographics.Patient_ID, Demographics.Last_Name, Demographics.First_Name,
    Event_Cath.Order_Number, Event_Cath.Date_of_Cath
Any help would be greatly appreciated. What I'm trying to do first group the records by PatientID, LastName, FirstName & Date. In the Details sections, I have all the procedures that were done. Each procedure would have both PCIProcedure & ProcedureDiagnostic. Then get the sum of PCIProcedure per group. Then I will evaluate the sum. It gets tricky because say you have 3 procedures and all 3 have the PCIProcedure having a value of 1. So when I get the sum, it is going to be three. The catch is I have to consider all three procedures as ONLY 1 count. That is why a simple sum formula will not work for me. I thought that by using a SQL expression, I will be able to add more logic for getting the true count. Thanks


Edited by josh2009 - 17 Feb 2010 at 9:53am
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 18 Feb 2010 at 6:39am
why not create a formula that only increments once.  Or how about counting the number in a group, since everything under that is, as a group 1.  Or how about a distinct count of PCIProcedure?
 
HTH
IP IP Logged
josh2009
Newbie
Newbie


Joined: 26 Jun 2009
Location: United States
Online Status: Offline
Posts: 16
Quote josh2009 Replybullet Posted: 18 Feb 2010 at 6:53am

Thanks for all the help. Here is what I'm doing - inside the group footer, I inserted a running total field where type of summary is average so I am able to get the average and I called it PCI Procedure Count. Next I created a formula (PCI Procedure Count CT) to evaluate the average because there could be 2 out of 4 procedure having a value of 1 so my average would be 0.5 -

 

if {#PCI Procedure Count} > 0 then 1 else 0

 

So I am getting a true count for each group. But the problem comes in when I try to get the totals from all the groups. Whe I attempt to create a formula for getting the sum of my "evaluated" average, I get an error message - "There is an error in the formula… The summary running toal field could not be created". Here is the formula -

 

Sum ({@PCI Procedure Count CT})

 

If you have any more suggestions, pls let me know. Thanks

IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 18 Feb 2010 at 11:39am
unfortunately, you can't use an aggregate function (sum, count, etc) on running totals and formulas.  I'm not good at running totals, they're DBlank's forte.  I use formulas, and I would create multiple formulas to run at the same time and reset them as needed so that all values display accurately.
 
HTH
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