Click here to Skip to main content
14,240,732 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello, I am try to combine 2 statements but have the first one's options limited by the second ones results. If the last statement is true I don't want '12' to be an available option in the drop down.


1) SELECT payment_plan.payment_plan_cde, payment_plan.pay_plan_desc
FROM payment_plan
Where payment_plan.payment_plan_cde in ('TF','12')

and

2) SELECT student_term_sum.hrs_enrolled
FROM student_term_sum
WHERE student_term_sum.id_num = @@HostID and student_term_sum.yr_cde = '2018' AND student_term_sum.trm_cde = '20' and student_term_sum.hrs_enrolled > 0

What I have tried:

I haven't tried any combination as of yet but I am not very good with complex SQL so I figured I better reach out for a little help.
Posted
Updated 5-Jun-18 0:40am
Comments
CHill60 5-Jun-18 4:09am
   
"If the last statement is true" ... what last statement? The 2nd SQL returns a number. Please try to make your problem clear
Moses Minor 5-Jun-18 7:05am
   
Sorry, here is what I am trying to do. If (SELECT student_term_sum.hrs_enrolled
FROM student_term_sum
WHERE student_term_sum.id_num = @@HostID and student_term_sum.yr_cde = '2018' AND student_term_sum.trm_cde = '20' and student_term_sum.hrs_enrolled > 0) returns null then I don't want '12' to be an option for this statement (
1) SELECT payment_plan.payment_plan_cde, payment_plan.pay_plan_desc
FROM payment_plan
Where payment_plan.payment_plan_cde in ('TF','12')).

So I want option '12' to be based on if the other statement results in a null

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Since your send query only returns a single field (possibly with many values?), look into subquery[^] formulated much like below:
SELECT * FROM Table1 WHERE field1 NOT IN (SELECT field2 FROM table 2)
There are variations on this and, under appropriate conditions (only return a single value from a single field) they can be in your SELECT as well.

Leaning more SQL and it gets easier to write:   Certain tasks were so useful they were made into language features.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100