MattSmithProg
Programmer
Hi,
I have a query that I have written and it works fine but it seems very inefficient. I would like to know if there is a better way to write it.
My table consists of this
NAT Finalisation_Result Finalisation_Date
4224 Adjust 01-04-2002
3224 Referred 05-04-2002
4224 Adjust 15-03-2002
My query is this.
Select NAT,
SUM(Case When Finalisation_Result = 'Adjusted' AND Finalisation_Date BETWEEN '01-04-2002' AND '30-04-2002' Then 1 Else 0 End) As Adjusted,
SUM(Case When Finalisation_Result = 'NFA' AND Finalisation_Date BETWEEN '01-04-2002' AND '30-04-2002' Then 1 Else 0 End) As NFA,
SUM(Case When Finalisation_Result = 'Post Issue Audit' AND Finalisation_Date BETWEEN '01-04-2002' AND '30-04-2002' Then 1 Else 0 End) As "Post Issue Audit",
SUM(Case When Finalisation_Result = 'Referred' AND Finalisation_Date BETWEEN '01-04-2002' AND '30-04-2002' Then 1 Else 0 End) As "Referred to other BSL/Section",
SUM(Case When Finalisation_Result = 'Adjusted' AND Finalisation_Date BETWEEN '01-07-2001' AND '30-06-2002' Then 1 Else 0 End) As "YTD Adjusted",
SUM(Case When Finalisation_Result = 'NFA' AND Finalisation_Date BETWEEN '01-07-2001' AND '30-06-2002' Then 1 Else 0 End) As "YTD NFA",
SUM(Case When Finalisation_Result = 'Post Issue Audit' AND Finalisation_Date BETWEEN '01-07-2001' AND '30-06-2002' Then 1 Else 0 End) As "YTD Post Issue Audit",
SUM(Case When Finalisation_Result = 'Referred' AND Finalisation_Date BETWEEN '01-07-2001' AND '30-06-2002' Then 1 Else 0 End) As "YTD Referred BSL/Section",
Count(NAT) As Total
From PTAPP_ACR_HRR_Inactive
Group By NAT;
Sorry about the formatting.
It basically will display in the first 5 columns the NAT and the monthly data then in the next 5 columns is the YTD data and the total YTD.
Thanks for your help. Matt Smith
No two nulls are the same
I have a query that I have written and it works fine but it seems very inefficient. I would like to know if there is a better way to write it.
My table consists of this
NAT Finalisation_Result Finalisation_Date
4224 Adjust 01-04-2002
3224 Referred 05-04-2002
4224 Adjust 15-03-2002
My query is this.
Select NAT,
SUM(Case When Finalisation_Result = 'Adjusted' AND Finalisation_Date BETWEEN '01-04-2002' AND '30-04-2002' Then 1 Else 0 End) As Adjusted,
SUM(Case When Finalisation_Result = 'NFA' AND Finalisation_Date BETWEEN '01-04-2002' AND '30-04-2002' Then 1 Else 0 End) As NFA,
SUM(Case When Finalisation_Result = 'Post Issue Audit' AND Finalisation_Date BETWEEN '01-04-2002' AND '30-04-2002' Then 1 Else 0 End) As "Post Issue Audit",
SUM(Case When Finalisation_Result = 'Referred' AND Finalisation_Date BETWEEN '01-04-2002' AND '30-04-2002' Then 1 Else 0 End) As "Referred to other BSL/Section",
SUM(Case When Finalisation_Result = 'Adjusted' AND Finalisation_Date BETWEEN '01-07-2001' AND '30-06-2002' Then 1 Else 0 End) As "YTD Adjusted",
SUM(Case When Finalisation_Result = 'NFA' AND Finalisation_Date BETWEEN '01-07-2001' AND '30-06-2002' Then 1 Else 0 End) As "YTD NFA",
SUM(Case When Finalisation_Result = 'Post Issue Audit' AND Finalisation_Date BETWEEN '01-07-2001' AND '30-06-2002' Then 1 Else 0 End) As "YTD Post Issue Audit",
SUM(Case When Finalisation_Result = 'Referred' AND Finalisation_Date BETWEEN '01-07-2001' AND '30-06-2002' Then 1 Else 0 End) As "YTD Referred BSL/Section",
Count(NAT) As Total
From PTAPP_ACR_HRR_Inactive
Group By NAT;
Sorry about the formatting.
It basically will display in the first 5 columns the NAT and the monthly data then in the next 5 columns is the YTD data and the total YTD.
Thanks for your help. Matt Smith
No two nulls are the same