I inherited a formula from my work predecessor that is nothing but problematic. I don't write or understand basic syntax, but that's what its written in, and it has a myriad of problems. Here it is:
Select case({vInsertionMaster.JobPaperGroupName}),
sum(case when DatePart(m,{vInsertionMaster.InsertionDate})=3 then 1 else 0 end )as janInsertionCount ,
sum(case when DatePart(m,{vInsertionMaster.InsertionDate})=4 then 1 else 0 end )as febInsertionCount ,
sum(case when DatePart(m,{vInsertionMaster.InsertionDate})=5 then 1 else 0 end )as MarInsertionCount ,
sum(case when DatePart(m,{vInsertionMaster.InsertionDate})=6 then 1 else 0 end )as AprInsertionCount ,
sum(case when DatePart(m,{vInsertionMaster.InsertionDate})=7 then 1 else 0 end )as MayInsertionCount ,
sum(case when DatePart(m,{vInsertionMaster.InsertionDate})=8 then 1 else 0 end )as JunInsertionCount ,
sum(case when DatePart(m,{vInsertionMaster.InsertionDate})=3 then {vInsertionMaster.InsertionAgencyGrossAmount} else 0 end )as janAgencyGross ,
sum(case when DatePart(m,{vInsertionMaster.InsertionDate})=4 then {vInsertionMaster.InsertionAgencyGrossAmount} else 0 end )as febAgencyGross ,
sum(case when DatePart(m,{vInsertionMaster.InsertionDate})=5 then {vInsertionMaster.InsertionAgencyGrossAmount} else 0 end )as MarAgencyGross ,
sum(case when DatePart(m,{vInsertionMaster.InsertionDate})=6 then {vInsertionMaster.InsertionAgencyGrossAmount} else 0 end )as AprAgencyGross ,
sum(case when DatePart(m,{vInsertionMaster.InsertionDate})=7 then {vInsertionMaster.InsertionAgencyGrossAmount} else 0 end )as MayAgencyGross ,
sum(case when DatePart(m,{vInsertionMaster.InsertionDate})=8 then {vInsertionMaster.InsertionAgencyGrossAmount} else 0 end )as JunAgencyGross from insertions,JobPapers where {vInsertionMaster.InsertionClientID}=16 and {vInsertionMaster.JobPaperID}={vInsertionMaster.InsertionJobPaperID} and {vInsertionMaster.InsertionDate}>='03/01/05' and {vInsertionMaster.InsertionDate}<='12/31/05' group by {vInsertionMaster.JobPaperGroupName} order by {vInsertionMaster.JobPaperGroupName}
The formula is in an accounting report that is (I believe) supposed to be figuring the sum of the Gross for each month. However, I'm not entirely sure, because it has never done so. :0 I am using CR9 on a SQL server, if that helps.
Let me know if I've left out any vital information. What do I need to do to correct the syntax errors here?
Thanks in advance!
LK
Select case({vInsertionMaster.JobPaperGroupName}),
sum(case when DatePart(m,{vInsertionMaster.InsertionDate})=3 then 1 else 0 end )as janInsertionCount ,
sum(case when DatePart(m,{vInsertionMaster.InsertionDate})=4 then 1 else 0 end )as febInsertionCount ,
sum(case when DatePart(m,{vInsertionMaster.InsertionDate})=5 then 1 else 0 end )as MarInsertionCount ,
sum(case when DatePart(m,{vInsertionMaster.InsertionDate})=6 then 1 else 0 end )as AprInsertionCount ,
sum(case when DatePart(m,{vInsertionMaster.InsertionDate})=7 then 1 else 0 end )as MayInsertionCount ,
sum(case when DatePart(m,{vInsertionMaster.InsertionDate})=8 then 1 else 0 end )as JunInsertionCount ,
sum(case when DatePart(m,{vInsertionMaster.InsertionDate})=3 then {vInsertionMaster.InsertionAgencyGrossAmount} else 0 end )as janAgencyGross ,
sum(case when DatePart(m,{vInsertionMaster.InsertionDate})=4 then {vInsertionMaster.InsertionAgencyGrossAmount} else 0 end )as febAgencyGross ,
sum(case when DatePart(m,{vInsertionMaster.InsertionDate})=5 then {vInsertionMaster.InsertionAgencyGrossAmount} else 0 end )as MarAgencyGross ,
sum(case when DatePart(m,{vInsertionMaster.InsertionDate})=6 then {vInsertionMaster.InsertionAgencyGrossAmount} else 0 end )as AprAgencyGross ,
sum(case when DatePart(m,{vInsertionMaster.InsertionDate})=7 then {vInsertionMaster.InsertionAgencyGrossAmount} else 0 end )as MayAgencyGross ,
sum(case when DatePart(m,{vInsertionMaster.InsertionDate})=8 then {vInsertionMaster.InsertionAgencyGrossAmount} else 0 end )as JunAgencyGross from insertions,JobPapers where {vInsertionMaster.InsertionClientID}=16 and {vInsertionMaster.JobPaperID}={vInsertionMaster.InsertionJobPaperID} and {vInsertionMaster.InsertionDate}>='03/01/05' and {vInsertionMaster.InsertionDate}<='12/31/05' group by {vInsertionMaster.JobPaperGroupName} order by {vInsertionMaster.JobPaperGroupName}
The formula is in an accounting report that is (I believe) supposed to be figuring the sum of the Gross for each month. However, I'm not entirely sure, because it has never done so. :0 I am using CR9 on a SQL server, if that helps.
Let me know if I've left out any vital information. What do I need to do to correct the syntax errors here?
Thanks in advance!
LK