sql - Return values based matching times and days -


i'm attempting match results of employees schedules vs reporting schedules. need output report shows reports , assigned them. place i'm having trouble based on day of week.

my reportschedule table looks this:

╔══════════════╦══════════════╦══════╦══════╦══════╦══════╦══════╦══════╦════╗ ║ reportid     ║ time         ║ m    ║ tu   ║ w    ║ th   ║ f    ║ sa   ║ su ║ ╠══════════════╬══════════════╬══════╬══════╬══════╬══════╬══════╬══════╬════╣ ║ 1001         ║ 06:18:00     ║ 1    ║ 1    ║ 1    ║ 1    ║ 1    ║ 0    ║  0 ║ ║ 1002         ║ 06:48:00     ║ 0    ║ 0    ║ 0    ║ 0    ║ 0    ║ 1    ║  1 ║ ║ 1003         ║ 07:18:00     ║ 1    ║ 1    ║ 1    ║ 1    ║ 1    ║ 1    ║  1 ║ ╚══════════════╩══════════════╩══════╩══════╩══════╩══════╩══════╩══════╩════╝ 

my employeesschedule table looks this:

╔════════════╦══════════╦═════════════╦═══════════╦═══╦════╦═══╦════╦═══╦════╦════╗ ║ employeeid ║ reportid ║ reportstart ║ reportend ║ m ║ tu ║ w ║ th ║ f ║ sa ║ su ║   ╠════════════╬══════════╬═════════════╬═══════════╬═══╬════╬═══╬════╬═══╬════╬════╣ ║      22001 ║     1001 ║ 05:00:00    ║ 12:00:00  ║ 1 ║  1 ║ 1 ║  1 ║ 1 ║  0 ║  0 ║   ║      22001 ║     1002 ║ 05:00:00    ║ 12:00:00  ║ 1 ║  1 ║ 1 ║  1 ║ 1 ║  0 ║  0 ║   ║      22001 ║     1003 ║ 05:00:00    ║ 12:00:00  ║ 1 ║  1 ║ 1 ║  1 ║ 1 ║  0 ║  0 ║   ║      22002 ║     1001 ║ 06:00:00    ║ 14:00:00  ║ 0 ║  0 ║ 0 ║  0 ║ 0 ║  1 ║  1 ║   ║      22002 ║     1002 ║ 06:00:00    ║ 14:00:00  ║ 0 ║  0 ║ 0 ║  0 ║ 0 ║  1 ║  1 ║   ║      22002 ║     1003 ║ 06:00:00    ║ 14:00:00  ║ 0 ║  0 ║ 0 ║  0 ║ 0 ║  1 ║  1 ║   ╚════════════╩══════════╩═════════════╩═══════════╩═══╩════╩═══╩════╩═══╩════╩════╝ 

what need based on above this:

╔════════════╦══════════╦══════════╦═══╦════╦═══╦════╦═══╦════╦════╗ ║ employeeid ║ reportid ║   time   ║ m ║ tu ║ w ║ th ║ f ║ sa ║ su ║ ╠════════════╬══════════╬══════════╬═══╬════╬═══╬════╬═══╬════╬════╣ ║      22001 ║     1001 ║ 06:18:00 ║ 1 ║  1 ║ 1 ║  1 ║ 1 ║  0 ║  0 ║ ║      22002 ║     1002 ║ 06:48:00 ║ 0 ║  0 ║ 0 ║  0 ║ 0 ║  1 ║  1 ║ ║      22001 ║     1003 ║ 07:18:00 ║ 1 ║  1 ║ 1 ║  1 ║ 1 ║  0 ║  0 ║ ║      22002 ║     1003 ║ 07:18:00 ║ 0 ║  0 ║ 0 ║  0 ║ 0 ║  1 ║  1 ║ ╚════════════╩══════════╩══════════╩═══╩════╩═══╩════╩═══╩════╩════╝ 

the query running below:

select employeeschedule.employeeid, reportschedule.reportid, reportschedule.time,      reportschedule.m, reportschedule.tu, reportschedule.w, reportschedule.th, reportschedule.f, reportschedule.sa, reportschedule.su reportschedule     inner join employeeschedule on reportschedule.reportid = employeeschedule.reportid (         reportschedule.time > employeeschedule.reportstart ,          reportschedule.time < employeeschedule.reportend ,         (             (reportschedule.m=1) , (reportschedule.m = employeeschedule.m) or              (reportschedule.tu=1) , (reportschedule.tu = employeeschedule.tu) or              (reportschedule.w=1) , (reportschedule.w = employeeschedule.w) or              (reportschedule.th=1) , (reportschedule.th = employeeschedule.th) or              (reportschedule.f=1) , (reportschedule.f = employeeschedule.f) or              (reportschedule.sa=1) , (reportschedule.sa = employeeschedule.sa) or              (reportschedule.su=1) , (reportschedule.su = employeeschedule.su)         )     ) 

the results returned not i'm looking not filtering out days of week employee doesn't report. here being returned:

╔════════════╦══════════╦══════════╦═══╦════╦═══╦════╦═══╦════╦════╗ ║ employeeid ║ reportid ║   time   ║ m ║ tu ║ w ║ th ║ f ║ sa ║ su ║ ╠════════════╬══════════╬══════════╬═══╬════╬═══╬════╬═══╬════╬════╣ ║      22001 ║     1001 ║ 06:18:00 ║ 1 ║  1 ║ 1 ║  1 ║ 1 ║  0 ║  0 ║ ║      22002 ║     1002 ║ 06:48:00 ║ 0 ║  0 ║ 0 ║  0 ║ 0 ║  1 ║  1 ║ ║      22001 ║     1003 ║ 07:18:00 ║ 1 ║  1 ║ 1 ║  1 ║ 1 ║  1 ║  1 ║ ║      22002 ║     1003 ║ 07:18:00 ║ 1 ║  1 ║ 1 ║  1 ║ 1 ║  1 ║  1 ║ ╚════════════╩══════════╩══════════╩═══╩════╩═══╩════╩═══╩════╩════╝ 

what need results i'm looking for?

add clause report <> 0? also, have report id = report id in statement - i'm not sure that's necessary that's join clause. still new sql, i'm not sure.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -