Hi
I have a script (SP) for reports. In the sales, I have to subtract TH.GoodsTotal for the jobs that have TD.Narrative LIKE 'VAT'. My issue is with the select bellow, appear only the jobs which have TD.Narrative LIKE 'VAT', and I need the sales for all the jobs (TD.Narrative has other values).
I don’t know what to do, maybe you can help.
SELECT
Analysis.JobNumber,
Analysis.Sales + Analysis.Charges - TH.GoodsTotal as Sales,
FJ.ReportingDate,
…
C.AccountNumber,
C.Name,
substring(TH.Or,2,7) JobNoTr,
TD.Narrative
FROM
(((Analysis WITH (READUNCOMMITTED)
INNER JOIN FJ WITH (READUNCOMMITTED)
ON Analysis.JobNumber=FJ.Number)
INNER JOIN C WITH (READUNCOMMITTED)
ON C.AccountNumber=Analysis.CustomerAccountNumber)
INNER JOIN TH WITH (READUNCOMMITTED)
ON Analysis.JobNumber=substring(TH.Or,2,7)
AND substring(TH.Or,1,1)='J')
INNER JOIN TD WITH (READUNCOMMITTED)
ON TH.Or=TD.Or
WHERE
YEAR(F.ReportingDate)= 2015
and MONTH(F.ReportingDate)= 12
….
AND TD.Narrative LIKE 'VAT'
Should be:
….
619 210 2015-12-15 00:00:00 41 XXX 619 ATE - (I don’t need to subtract GoodsTotal)
679 4429 2015-12-04 00:00:00 19 YYY 679 VAT - (I subtracted GoodsTotal)
738 436 2015-12-05 00:00:00 19 YYY 738 ATI - (I don’t need to subtract GoodsTotal)
618 4253 2015-12-15 00:00:00 41 XXX 618 VAT - (I subtracted GoodsTotal)
502 4309 2015-12-05 00:00:00 19 XXX 502 VAT - (I subtracted GoodsTotal)
299 1549 2015-12-12 00:00:00 42 ZZZ 299 VAT - (I subtracted GoodsTotal)
……..
I have a script (SP) for reports. In the sales, I have to subtract TH.GoodsTotal for the jobs that have TD.Narrative LIKE 'VAT'. My issue is with the select bellow, appear only the jobs which have TD.Narrative LIKE 'VAT', and I need the sales for all the jobs (TD.Narrative has other values).
I don’t know what to do, maybe you can help.
SELECT
Analysis.JobNumber,
Analysis.Sales + Analysis.Charges - TH.GoodsTotal as Sales,
FJ.ReportingDate,
…
C.AccountNumber,
C.Name,
substring(TH.Or,2,7) JobNoTr,
TD.Narrative
FROM
(((Analysis WITH (READUNCOMMITTED)
INNER JOIN FJ WITH (READUNCOMMITTED)
ON Analysis.JobNumber=FJ.Number)
INNER JOIN C WITH (READUNCOMMITTED)
ON C.AccountNumber=Analysis.CustomerAccountNumber)
INNER JOIN TH WITH (READUNCOMMITTED)
ON Analysis.JobNumber=substring(TH.Or,2,7)
AND substring(TH.Or,1,1)='J')
INNER JOIN TD WITH (READUNCOMMITTED)
ON TH.Or=TD.Or
WHERE
YEAR(F.ReportingDate)= 2015
and MONTH(F.ReportingDate)= 12
….
AND TD.Narrative LIKE 'VAT'
Should be:
….
619 210 2015-12-15 00:00:00 41 XXX 619 ATE - (I don’t need to subtract GoodsTotal)
679 4429 2015-12-04 00:00:00 19 YYY 679 VAT - (I subtracted GoodsTotal)
738 436 2015-12-05 00:00:00 19 YYY 738 ATI - (I don’t need to subtract GoodsTotal)
618 4253 2015-12-15 00:00:00 41 XXX 618 VAT - (I subtracted GoodsTotal)
502 4309 2015-12-05 00:00:00 19 XXX 502 VAT - (I subtracted GoodsTotal)
299 1549 2015-12-12 00:00:00 42 ZZZ 299 VAT - (I subtracted GoodsTotal)
……..