sql - Converting DatePart and grouping on one line -


i'm doing best turn days of week x can mark them on weekly schedule - combining them on 1 line crux.

expected output:

agrmntid    description    repairid    su  m  tu  w  th  f  sa 2           landscaping    2                  x 3           landscaping    2               x  x   x  x   x  x 

current output:

agrmntid    description    repairid 2           landscaping    2 

current code:

select agreements.agrmntid, laborcodetypes.description,   agreementschedules.repairid agreements inner join   agreementschedules on agreements.agrmntid = agreementschedules.agrmntid   inner join   laborcodetypes on laborcodetypes.repairid = agreementschedules.repairid   inner join   (select agreementschedules.agrmntid, agreementschedules.repairid, case         when datepart(dw, agreementschedules.scheddate) = 1 'x'       end sunday     agreementschedules     agreementschedules.repairid = 2     union     select agreementschedules.agrmntid, agreementschedules.repairid, case         when datepart(dw, agreementschedules.scheddate) = 2 'x'       end monday     agreementschedules     agreementschedules.repairid = 2     union     select agreementschedules.agrmntid, agreementschedules.repairid, case         when datepart(dw, agreementschedules.scheddate) = 3 'x'       end tuesday     agreementschedules     agreementschedules.repairid = 2) sched on sched.agrmntid =     agreements.agrmntid group agreements.agrmntid, laborcodetypes.description,   agreementschedules.repairid having agreementschedules.repairid = 2 

i have many examples of how i've failed, if helps solve this. tips appreciated - thank in advance!!

if provide create table scripts , sample data, can vet this, @ first scratch:

select     a.agrmntid,     lct.description,     s.repairid,     days.sunday, days.monday, days.tuesday, days.wednesday, days.thursday, days.friday, days.saturday     agreements     inner join agreementschedules s on a.agrmntid = s.agrmntid     inner join laborcodetypes lct on s.repairid = lct.repairid     inner join         (         select             agrmntid, repairid, "1" sunday, "2" monday, "3" tuesday, "4" wednesday, "5" thursday, "6" friday, "7" saturday                     (             select distinct                 agrmntd, repairid, datepart(weekday, scheddate) dayofweek                             agreementschedules             ) x         pivot             (min(agrmntid) dayofweek in ("1", "2", "3", "4", "5", "6", "7")) y         ) days on a.agrmntid = days.agrmntid , s.repairid = days.repairid 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -