kryptkitten
Registered User.
- Local time
- Today, 15:19
- Joined
- Jul 19, 2010
- Messages
- 34
Hi All -
We are in the process of trying to move over a bunch of queries from Access 2007 to SQL Server 2008. I am having some difficulty trying to figure out how to convert the following code, which is a crosstab query in Access, to a pivot table in SQL Server. I believe this is one of the more complex ones.
TRANSFORM Count(dbo_v_CCP_SCCA_EventSummary.Event_Id) AS CountOfEvent_Id
SELECT dbo_vLabTestTypes.Problem, dbo_v_CCP_SCCA_EventSummary.Location_Service_Description
FROM dbo_v_CCP_SCCA_EventSummary INNER JOIN dbo_vLabTestTypes ON dbo_v_CCP_SCCA_EventSummary.Event_Id = dbo_vLabTestTypes.Event_ID
WHERE (((dbo_v_CCP_SCCA_EventSummary.Event_Type_Level_1)="Laboratory test"))
GROUP BY dbo_vLabTestTypes.Problem, dbo_v_CCP_SCCA_EventSummary.Location_Service_Description
PIVOT Year([Event_Occurence_Date]) & " Q" & DatePart("q",[Event_Occurence_Date]);
I have attached an Excel spreadsheet so you can see what the code produces.
I have been googling this to death without a whole lot of success so thought I would check here to see if anyone has had some success with making the conversion.
Thanks in advance for the assistance!
Stacy
We are in the process of trying to move over a bunch of queries from Access 2007 to SQL Server 2008. I am having some difficulty trying to figure out how to convert the following code, which is a crosstab query in Access, to a pivot table in SQL Server. I believe this is one of the more complex ones.
TRANSFORM Count(dbo_v_CCP_SCCA_EventSummary.Event_Id) AS CountOfEvent_Id
SELECT dbo_vLabTestTypes.Problem, dbo_v_CCP_SCCA_EventSummary.Location_Service_Description
FROM dbo_v_CCP_SCCA_EventSummary INNER JOIN dbo_vLabTestTypes ON dbo_v_CCP_SCCA_EventSummary.Event_Id = dbo_vLabTestTypes.Event_ID
WHERE (((dbo_v_CCP_SCCA_EventSummary.Event_Type_Level_1)="Laboratory test"))
GROUP BY dbo_vLabTestTypes.Problem, dbo_v_CCP_SCCA_EventSummary.Location_Service_Description
PIVOT Year([Event_Occurence_Date]) & " Q" & DatePart("q",[Event_Occurence_Date]);
I have attached an Excel spreadsheet so you can see what the code produces.
I have been googling this to death without a whole lot of success so thought I would check here to see if anyone has had some success with making the conversion.
Thanks in advance for the assistance!
Stacy
Attachments
Last edited: