Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
string query = "select ad.student_id,ad.full_name from add_student ad inner join billing b on ad.student_id = b.student_id where month (b.fee_of_month) = month(#"+DateTime.Now.ToShortDateString()+"#) and year(b.fee_of_month)= year(#"+DateTime.Now.ToShortDateString()+"#)";


I am using above query to retrieve record of those students that have paid fees for this month. This query is working fine.

I want a new query to retrieve rows for those students who have not paid their fees.

If I use query like below, then it will not return rows as expected. Please suggest a query that I can use to achieve my task. Thank you.

string query = "select ad.student_id,ad.full_name from add_student ad inner join billing b on ad.student_id = b.student_id where month (b.fee_of_month) <> month(#"+DateTime.Now.ToShortDateString()+"#) and year(b.fee_of_month)= year(#"+DateTime.Now.ToShortDateString()+"#)";
Posted
Updated 5-Mar-13 7:12am
v5
Comments
Richard C Bishop 5-Mar-13 11:38am    
You will have to change your WHERE clause to check for a column related to the fees.
Sergey Alexandrovich Kryukov 5-Mar-13 11:40am    
Just a warning: even though it makes sense, formally it's not a question. Please, try to make all "questions" on this forum shaped as distinct questions.

This is the reason: you want it because the forum is overwhelmed with non-questions these days. You don't want your post to be accidentally removed or reported for abuse...

—SA
Harpreet_125 5-Mar-13 11:49am    
can you please suggest me query..

Your new query will look something like this. Sorry, I do not have time to build a test case to test it for you. The concept is that you select from billing those student_ids that have paid and from add_student you select those student_ids that are not in the set of those that have paid. I hope this helps you.

string query = "select ad.student_id,ad.full_name from add_student ad where ad.student_id not in (select b.student_id from billing b where month (b.fee_of_month) = month(#"+DateTime.Now.ToShortDateString()+"#) and year(b.fee_of_month)= year(#"+DateTime.Now.ToShortDateString()+"#))";
 
Share this answer
 
Comments
Maciej Los 5-Mar-13 12:25pm    
Good job, +5!
use
SQL
SELECT * FROM add_student ad inner join billing b on ad.student_id = b.student_id HAVING  (select ad.student_id,ad.full_name from add_student ad inner join billing b on ad.student_id = b.student_id where month (b.fee_of_month) = month(#"+DateTime.Now.ToShortDateString()+"#) and year(b.fee_of_month)= year(#"+DateTime.Now.ToShortDateString()+"#))
 
Share this answer
 
v3

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900