Here's the deal --
I need a table to show me certain columns only for those students that meet a certain criteria. This is done through a series of joins. All of my table works perfectly, except for the last join I need.
delete from Manual.dbo.FedFundStudents
insert into Manual.dbo.FedFundStudents (cwid,FN,MI,LN,awardtype,amount,POE)
select distinct alternate_id ,
first_name,
middle_init,
last_name,
fund_name,
scheduled_amount,
poe_token
from student s
join stu_award_year say on s.student_token=say.student_token
join stu_award sa on say.stu_award_year_token=sa.stu_award_year_token
join stu_award_transactions sat on sa.stu_award_token = sat.stu_award_token
join user_string us1 on say.stu_award_year_token=us1.stu_award_year_token
join user_int ui on say.stu_award_year_token=ui.stu_award_year_token
where say.award_year_token > 2013
and alternate_id is not null
and scheduled_amount >0
and (fund_ay_token='15666' or
fund_ay_token='16304' or
fund_ay_token='15667' or
fund_ay_token='15663' or
fund_ay_token='16276' or
fund_ay_token='16277' or
fund_ay_token='16274' or
fund_ay_token='16275' or
fund_ay_token='16361')
select * from Manual.dbo.FedFundStudents
order by CWID, AwardType, POE
I want to replace all of the "fund_ay_token=''" where clauses with one clause that says
"where fund_source='f'". The fund_source column comes from a table called Funds, which I thought I could join using: join funds f1 on say.stu_award_year_token=f1.stu_award_year_token
I thought it should look like this:
delete from Manual.dbo.FedFundStudents
insert into Manual.dbo.FedFundStudents (cwid,FN,MI,LN,awardtype,amount,POE)
select distinct alternate_id ,
first_name,
middle_init,
last_name,
fund_name,
scheduled_amount,
poe_token
from student s
join stu_award_year say on s.student_token=say.student_token
join stu_award sa on say.stu_award_year_token=sa.stu_award_year_token
join stu_award_transactions sat on sa.stu_award_token = sat.stu_award_token
join user_string us1 on say.stu_award_year_token=us1.stu_award_year_token
join user_int ui on say.stu_award_year_token=ui.stu_award_year_token
join funds f1 on say.award_year_token=f1.award_year_token
where say.award_year_token > 2013
and alternate_id is not null
and scheduled_amount >0
and fund_source='f'
select * from Manual.dbo.FedFundStudents
order by CWID, AwardType, POE
However, my return is really all records where a fund_source exists, not ONLY those where fund_source='f'
Any guidance?
THANKS!