Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
i want to check time conflict in student course system using sql server so that student can't add course to his plan if it con conflicts in time with another course for that student.

i try the following sql statments and it works correctly in the same table (CouseSection) and it gives me that course (system analysis) conflict with (hardware) But not for the same student.

i want to get the same result for the same student (student_id)
i don't know how to get the same result using student_id

here is sql statement
SQL
SELECT     
    t1.crs_sec_id, 
    t1.start_time, 
    t1.end_time, 
    t2.crs_sec_id AS overlapid
FROM         
    CourseSection AS t1 
    INNER JOIN CourseSection AS t2 
    ON t1.start_time < t2.end_time AND t1.end_time > t2.start_time 
    AND t1.date = t2.date
    AND t1.crs_sec_id <> t2.crs_sec_id
WHERE     
    (t1.Course_id = 4)


it gives me this result:
crs_sec_id	- start_time	   -      end_time	 -       overlapid
5	       -  10:00:00.0000000 - 	12:00:00.0000000  -	1

i want to get the same result for the same student (student_id)
i don't know how to get the same result using student_id?
where i can put the (student_id) in the previous statement to get the same result?

here is the relationships in my database
http://www.4shared.com/photo/ice8bR9Qba/db_online.html[^]

and student page
http://www.4shared.com/photo/BxqqgUcCba/page.html[^]

my try in sql server
http://www.4shared.com/photo/7dJyXY0Mce/dbconflict.html[^]
Posted
Updated 22-Mar-14 7:39am
v2

1 solution

Try this...
SQL
SELECT     
    stdc.std_id,
    cs1.crs_sec_id, 
    cs1.start_time, 
    cs1.end_time, 
    cs2.crs_sec_id AS overlapid
FROM         
    StudentCource stdc
    INNER JOIN CourseSection AS cs1
        ON stdc.crs_sec_id = cs1.crs_sec_id 
    INNER JOIN CourseSection AS cs2
        ON stdc.crs_sec_id = cs2.crs_sec_id 
        AND cs1.crs_sec_id <> cs2.crs_sec_id
        AND cs1.date = cs2.date
        (   
            cs2.start_time BETWEEN cs1.start_time AND cs1.end_time 
            OR  
            cs2.end_time BETWEEN cs1.start_time AND cs1.end_time
        )
WHERE     
    cs2.crs_sec_id IS NOT NULL

Happy Coding!
:)
 
Share this answer
 
v2
Comments
progahmed 22-Mar-14 15:51pm    
Sorry, dosen't work
thank you Aarti Meswania for your help
progahmed 22-Mar-14 15:57pm    
Any other helps please?

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