I’m having a terrible time trying to figure out how to add XML PATH to my code to concatenate some information, let alone understanding how XML PATH works. I’ve spent the better part of the last two days working on this and would appreciate some help!!
Here’s the code I’m working with:
Select Top 100 Percent Agreements.AgrmntID, Agreements.Description As
AgrmntDesc, Agreements.Status, AgreementSchedules.SchedDate, DateName(dw,
AgreementSchedules.SchedDate), LaborCodeTypes.Description As LaborCode,
Customers.CustName, Customers.CompanyName, JobSites.SiteName,
AgreementSchedules.AgrmntSchedID
From Agreements Inner Join
AgreementTypes On Agreements.AgrmntTypeID = AgreementTypes.AgrmntTypeID
Inner Join
AgreementSchedules On Agreements.AgrmntID = AgreementSchedules.AgrmntID
Inner Join
Customers On Agreements.CustID = Customers.CustID Inner Join
JobSites On Agreements.CustSiteID = JobSites.CustSiteID Left Outer Join
LaborCodeTypes On AgreementSchedules.RepairID = LaborCodeTypes.RepairID
Where Agreements.Status = 2 And Month(AgreementSchedules.SchedDate) =
Month(GetDate())
Sample Data:
| AgreementID | LaborCodeTypes.Description | DateName(dw, AgreementSchedules.SchedDate)|
| - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -|
| 1 | Landscaping | Tuesday |
| 1 | Landscaping | Friday |
| 1 | Sweeping | Monday |
| 1 | Sweeping | Wednesday |
| 1 | Sweeping | Friday |
| 2 | Landscaping | Monday |
Expected Output:
| AgreementID | LaborCode | Days Of Week |
| - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 1 | Landscaping | Tuesday, Friday |
| 1 | Sweeping | Monday, Wednesday, Friday |
| 2 | Landscaping | Monday |
I would greatly, greatly appreciate it if someone could help me.
Thank you in advance!!
Jamie S
SQL Fiddle