Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Parameter for SQL query Post Reply Post New Topic
Author Message
bluelake
Newbie
Newbie
Avatar

Joined: 08 Jul 2010
Online Status: Offline
Posts: 24
Quote bluelake Replybullet Topic: Parameter for SQL query
    Posted: 14 Jun 2012 at 6:21am
I am teaching myself basic SQL use in CR.  I've managed to create a report that works (Yea!!).  The reason I want to use the SQL query in the first place is this.  I have a parameter {Patient Number} that I want to look in fields from either of two tables.  I've tried several angles with no luck. This is what I want:

SELECT
"Patient_Number",
"patient1_num",
"patient2_num",
"patient3_num"

FROM
"Table 1",
"Table 2"

WHERE

{Patient Number} = "Patient_Number"

So Far it works fine

I want to add: 

OR {Patient Number} = "patient1_num"
OR {Patient Number} = "patient2_num"
OR {Patient Number} = "patient3_num"

I've tried IN and various OR statements, but can't get to only pull those records where the {Patient Number} is in other tables/columns

Can someone show me what I'm missing?
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 14 Jun 2012 at 7:07am
I'm not sure that CR is the tool for learning SQL.
 
what is missing is how table1 and table2 relate to each other...
 
a better sql statement would be something like:
select
 t1.patient_number,
 t2.patient1_number,
 t2.patient2_number,
 t2.patient3_number
from table1 as t1
  join table2 as t2
    on t1.somefield = t2.somefield
where {patient number} = t1.patient_number
 or {patient number} = t2.patient1_number
etc
 
HTH
 
IP IP Logged
Post Reply Post New Topic
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



This page was generated in 0.031 seconds.