How to get db results to be column headings?
Posted on 2008-06-17
I currently have a SQL statement that gives me the corrert results, but I need the results to be formatted in a different way. For example, I grab 5 records from my database. Within those results, I have 5 dates, all being Friday dates. Instead of having 5 records, I need it to be 1 record and those 5 dates need to be column headings with other fields in the result set being under them. Here is my current Stored Procedure that works, it just gives me a record for every date, instead of making those dates column headings. Hopefully this makes a little bit of sense and somebody can push me in the right direction. Thanks in advance.
CREATE PROCEDURE dbo.ManPower_GetProjectDataByProjectID
@ProjectID int = NULL
SELECT Manpower_Employees.FirstName + ' ' + Manpower_Employees.LastName AS EmployeeName,
RIGHT OUTER JOIN Manpower_ProjectDateHours ON Manpower_Fridays.Fridays_ID = Manpower_ProjectDateHours.DateID
LEFT OUTER JOIN Manpower_Projects ON Manpower_ProjectDateHours.ProjectID = Manpower_Projects.Projects_ID
LEFT OUTER JOIN Manpower_Departments
RIGHT OUTER JOIN Manpower_Employees ON Manpower_Departments.Departments_ID = Manpower_Employees.DepartmentID ON
Manpower_ProjectDateHours.EmployeeID = Manpower_Employees.Employees_ID
WHERE Manpower_Projects.Projects_ID = @ProjectID