Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

How to solve this? Expand / Collapse
Author
Message
Posted Wednesday, January 30, 2008 2:37 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, February 19, 2014 10:23 PM
Points: 174, Visits: 348
I have this query

select distinct p.first_name
,p.last_name
,'class level' = case when a.credits + t.earned_credits between 1 and 32 and a.program ='ft'then 'F1'
when a.credits + t.earned_credits between 33 and 61 and a.program ='ft' then 'F2'
when a.credits + t.earned_credits >= 62 and a.program ='ft'then 'F3'
when a.credits + t.earned_credits between 1 and 25 and a.program ='pt'then 'P1'
when a.credits + t.earned_credits between 26 and 47 and a.program ='pt'then 'P2'
when a.credits + t.earned_credits between 48 and 70 and a.program ='pt'then 'P3'
when a.credits + t.earned_credits >= 71 and a.program ='pt'then 'P4'
end
from people as p
inner join academic as a
on p.people_code_id=a.people_code_id
inner join transcriptgpa as t
on p.people_code_id=t.people_code_id
where t.record_type='O'
and a.academic_term='Spring'
and a.academic_year='2008'
and t.academic_term='Fall'
and t.academic_year='2007'
and a.enroll_separation ='enrl'
and a.academic_session='main'
and (a.program ='ft' or a.program='pt')
order by 'class level', p.first_name

Which is correct, BUT, not everyone has data in the transcriptgpa table, for fall 2007 but, i still need to pull them based on their a.credits. if they dont have anything in the transcriptgpa table for fall 2007. How can i do this?
Post #449707
Posted Wednesday, January 30, 2008 2:39 PM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Sunday, April 13, 2014 9:51 PM
Points: 4,570, Visits: 8,315
LEFT join transcriptgpa

And move
t.record_type='O'
and t.academic_term='Fall'
and t.academic_year='2007'
from "WHERE" to "ON"
Post #449709
Posted Wednesday, January 30, 2008 5:02 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, February 19, 2014 10:23 PM
Points: 174, Visits: 348
Can you clarify? Im not sure how to move them to the on line. The joins confuses me? Can you write an example?
Post #449751
Posted Wednesday, January 30, 2008 5:20 PM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Sunday, April 13, 2014 9:51 PM
Points: 4,570, Visits: 8,315
...
left join transcriptgpa as t on
p.people_code_id=t.people_code_id
and t.record_type='O'
and t.academic_term='Fall'
and t.academic_year='2007'
where a.academic_term='Spring'
and a.academic_year='2008'
and a.enroll_separation ='enrl'
and a.academic_session='main'
and (a.program ='ft' or a.program='pt')

Post #449757
Posted Wednesday, January 30, 2008 5:25 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, February 19, 2014 10:23 PM
Points: 174, Visits: 348
Thanks!! It worked. Now i see the people who were previosuly missing. Ive never seen a join created like this, can you explain how exactly this is working? Im looking at it, and its just not jumping out yet. I really appreciate the help btw.
Post #449760
Posted Wednesday, January 30, 2008 5:35 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, February 19, 2014 10:23 PM
Points: 174, Visits: 348
After further review it looks like that by adding those as a left outer join by using
on p.people_code_id=t.people_code_id
and t.record_type='O'
and t.academic_term='Fall'
and t.academic_year='2007'

its pulling IF they have a fall 2007 "o" record. If not, its just pulling their people record and using the data contained in the academic table for my case calulations, using the rest of the where clause? So my Case statement is seeing nothing in the transcriptgpa table, then using the rest of the where clause for definition. Am i close?

*edit*

I also notice now the people who are appearing are showing a class level of "null". Probably because they dont have any data in the transcriptgpa table, is their any way to use only the values in the acadmic table IF, they dont have data in the transcriptgpa table? Does this make sense?
Post #449761
Posted Wednesday, January 30, 2008 5:59 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, January 21, 2014 9:38 PM
Points: 144, Visits: 447
Add IsNull() or Coalesce() around the transcription credits, like this:

select distinct p.first_name
,p.last_name
,'class level' = case when a.credits + t.earned_credits between 1 and 32 and a.program ='ft'then 'F1'
when a.credits + isnull(t.earned_credits, 0) between 33 and 61 and a.program ='ft' then 'F2'
when a.credits + isnull(t.earned_credits, 0) >= 62 and a.program ='ft'then 'F3'
when a.credits + isnull(t.earned_credits, 0) between 1 and 25 and a.program ='pt'then 'P1'
when a.credits + isnull(t.earned_credits, 0) between 26 and 47 and a.program ='pt'then 'P2'
when a.credits + isnull(t.earned_credits, 0) between 48 and 70 and a.program ='pt'then 'P3'
when a.credits + isnull(t.earned_credits, 0) >= 71 and a.program ='pt'then 'P4'
end
..........etc



Post #449765
Posted Thursday, January 31, 2008 10:17 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, February 19, 2014 10:23 PM
Points: 174, Visits: 348
One more thing i need to add...On their transcript gpa record, when it is pulling t.earned credits, their is also a trans seq number of either 001 or 002. Not everyone has a 002 record, BUT, if they do i need to use that record, if they dont have a trans seq of 002, then i need to use their 001 record. Is it possible to incoporate this into my code? This is what i have thus far, which is pulling everyone correctly, BUT, some people are appearing twice because they have both a trans seq 001 and 002 record, it should only be pulling their 002 record if they have it, if not, then 001.

select distinct p.first_name
,p.last_name
,'class level' = case when a.credits + isnull(t.earned_credits,0) between 1 and 32 and a.program ='ft'then 'F1' when a.credits + isnull(t.earned_credits, 0) between 33 and 61 and a.program ='ft' then 'F2'when a.credits + isnull(t.earned_credits, 0) >= 62 and a.program ='ft'then 'F3' when a.credits + isnull(t.earned_credits, 0) between 1 and 25 and a.program ='pt'then 'P1'
when a.credits + isnull(t.earned_credits, 0) between 26 and 47 and a.program ='pt'then 'P2'
when a.credits + isnull(t.earned_credits, 0) between 48 and 70 and a.program ='pt'then 'P3'
when a.credits + isnull(t.earned_credits, 0) >= 71 and a.program ='pt'then 'P4'
end
from people as p
inner join academic as a
on p.people_code_id=a.people_code_id
left outer join transcriptgpa as t
on p.people_code_id=t.people_code_id
and t.record_type='O' and t.academic_term='Fall'--records in the transcript gpa table
and t.academic_year='2007'
where a.academic_term='Spring'
and a.academic_year='2008'
and a.enroll_separation ='enrl'
and a.academic_session='main'
and (a.program ='ft' or a.program='pt')
order by 'class level'
Post #450071
Posted Friday, February 01, 2008 8:48 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, February 19, 2014 10:23 PM
Points: 174, Visits: 348
still looking for an answer to the trans seq question, anyone?
Post #450556
Posted Friday, February 01, 2008 10:26 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, January 21, 2014 9:38 PM
Points: 144, Visits: 447
-- One way is to join the transcript table twice and switch from isNull() to coalesce().
select distinct
p.first_name
,p.last_name
,'class level' = case
when a.credits + coalesce(t2.earned_credits, t1.earned_credits, 0) between 1 and 32 and a.program ='ft'then 'F1'
when a.credits + coalesce(t2.earned_credits, t1.earned_credits, 0) between 33 and 61 and a.program ='ft' then 'F2'
when a.credits + coalesce(t2.earned_credits, t1.earned_credits, 0) >= 62 and a.program ='ft'then 'F3'
when a.credits + coalesce(t2.earned_credits, t1.earned_credits, 0) between 1 and 25 and a.program ='pt'then 'P1'
when a.credits + coalesce(t2.earned_credits, t1.earned_credits, 0) between 26 and 47 and a.program ='pt'then 'P2'
when a.credits + coalesce(t2.earned_credits, t1.earned_credits, 0) between 48 and 70 and a.program ='pt'then 'P3'
when a.credits + coalesce(t2.earned_credits, t1.earned_credits, 0) >= 71 and a.program ='pt'then 'P4'
end
from people as p
inner join academic as a
on p.people_code_id=a.people_code_id

left outer join transcriptgpa as t2
on p.people_code_id=t2.people_code_id
and t2.record_type='O'
and t2.academic_term='Fall'
and t2.academic_year='2007'
and t2.seqno = '002'

left outer join transcriptgpa as t1
on p.people_code_id=t1.people_code_id
and t1.record_type='O'
and t1.academic_term='Fall'
and t1.academic_year='2007'
and t1.seqno = '001'

where a.academic_term='Spring'
and a.academic_year='2008'
and a.enroll_separation ='enrl'
and a.academic_session='main'
and (a.program ='ft' or a.program='pt')
order by 'class level'



Post #450635
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse