Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Can Crystal do this? Post Reply Post New Topic
Author Message
User
Newbie
Newbie


Joined: 08 Jul 2010
Location: United States
Online Status: Offline
Posts: 4
Quote User Replybullet Topic: Can Crystal do this?
     Posted: 08 Jul 2010 at 4:31am
< ="Content-" content="text/; charset=utf-8">< name="ProgId" content="Word.">< name="Generator" content="Microsoft Word 12">< name="Originator" content="Microsoft Word 12"><>

Hi there, I have been on this forum a number of times before and have always received satisfactory responses for my questions.  However, I have always struggled to use crystal for running subqueries i.e. having one main report running on the results of a sub query. Below is what, I am trying to achieve is:

SELECT DISTINCT A. physician_name, A.account_number, A.date_of_service, A.patient_type, A.code

FROM error_fact A

WHERE C.account_number IN

(SELECT account_number FROM error_fact C

WHERE C.date_of_service >= "01/01/2010" AND C.patient_type = “O” AND C.code IN ("93307","93325","93320")))

 

In the aforementioned, I can’t apply the filter in the main query because if I do I will see accounts and their related information with codes in the condition (this is what I want) and not see other codes (this is not what I want) i.e. if an account has 6 codes, out of which 3 are the ones in the filter condition, I want to see all 6 and not just 3 which match the condition. That is why, I filter out accounts satisfying the condition and then query out all the information (everything I need on an account) in the main query.

For clarity, please see the example below

Account      Codes

A                   93307

                      93325

                      98789

 

B                   10000

 

If I apply filter in the main query, my result looks like

A       93307

          93325

 

And it does not show ‘98789’ (this is not acceptable), however it only shows account A and not B (this is desired)    

I want to know if this is possible in Crystal by means of passing the accounts from a sub-query to main query. Also, please notice that it will be a list of accounts that will have to go from sub-query to main query.

P.S. Each account has multiple codes.

IP IP Logged
rahulwalawalkar
Senior Member
Senior Member
Avatar

Joined: 08 Jun 2007
Location: United Kingdom
Online Status: Offline
Posts: 731
Quote rahulwalawalkar Replybullet Posted: 08 Jul 2010 at 4:39am
Hi,
 
You can try the following
*Add the subquery as command object  and then join the main table may be a left outer join.
*Or Create view or stored procedure in Database and use that in the report.
 
I have not tested the first option but the second one will definitely work i think
 
Cheers
Rahul


Edited by rahulwalawalkar - 08 Jul 2010 at 4:40am
IP IP Logged
User
Newbie
Newbie


Joined: 08 Jul 2010
Location: United States
Online Status: Offline
Posts: 4
Quote User Replybullet Posted: 08 Jul 2010 at 4:44am
Thanks for replying. I have tried the second option, it works. However, I am looking to see if the something like the first one will work?


IP IP Logged
rahulwalawalkar
Senior Member
Senior Member
Avatar

Joined: 08 Jun 2007
Location: United Kingdom
Online Status: Offline
Posts: 731
Quote rahulwalawalkar Replybullet Posted: 08 Jul 2010 at 4:47am
hmm will test when i go home and post the results
 
cheers
Rahul
IP IP Logged
User
Newbie
Newbie


Joined: 08 Jul 2010
Location: United States
Online Status: Offline
Posts: 4
Quote User Replybullet Posted: 08 Jul 2010 at 5:05am
thanks for the help. Appreciate that.
IP IP Logged
rahulwalawalkar
Senior Member
Senior Member
Avatar

Joined: 08 Jun 2007
Location: United Kingdom
Online Status: Offline
Posts: 731
Quote rahulwalawalkar Replybullet Posted: 08 Jul 2010 at 6:54am
Hi
Please can you post the table structure and data types, does the data come from same table
 
Cheers
Rahul
 
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