Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Crystal Reports equivalent to sql query Post Reply Post New Topic
Author Message
JasonLee07
Newbie
Newbie


Joined: 06 Jul 2010
Location: United States
Online Status: Offline
Posts: 6
Quote JasonLee07 Replybullet Topic: Crystal Reports equivalent to sql query
     Posted: 06 Jan 2011 at 5:54am
Greetings.

I started out trying to do this in Crystal Reports 2k8 but couldnt quite accomplish what I was looking for.  And the only way I could think to do this in sql was the following:

select s.pupil_number from students s
where s.grade = '09'
and s.school = 60
and s.withdraw_date is null
minus
select s.pupil_number from students s, course_selections cs, courses c
where s.pupil_number = cs.pupil_number
and cs.course_id = c.id
and c.course_code = '0223'
and s.grade = '09'
and s.school = 60
and c.year = 2010
and s.withdraw_date is null;

The goal is just to find out which kids are not taking the course 0223.



Jason Lee
Developer
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 06 Jan 2011 at 7:08am
Pull all of the records you want to evaluate then create a Running Total to get a total for those taking those course and then subtract that from all
RT
Name=TakingCourse
Field to summarize=pupil_number
Type = DistinctCOunt
Evalaute = use a formula
something like
 cs.course_id = c.id
and c.course_code = '0223'
and s.grade = '09'
and s.school = 60
and c.year = 2010
and s.withdraw_date is null
reset=never
 
distinctcount(cs.pupil_number) - #TakingCourse
IP IP Logged
asam
Newbie
Newbie
Avatar

Joined: 08 Jan 2011
Online Status: Offline
Posts: 20
Quote asam Replybullet Posted: 08 Jan 2011 at 8:22am
Have you tried:
 
select s.pupil_number from students s
where s.grade = '09'
and s.school = 60
and s.withdraw_date is null
and s.pupil_number not IN
(
select s.pupil_number
from students s
 inner join course_selections cs
 ON s.pupil_number = cs.pupil_number
 inner join courses c
 ON cs.course_id = c.id
Where c.course_code = '0223'
and s.grade = '09'
and s.school = 60
and c.year = 2010
and s.withdraw_date is null
);
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