Hi all, Been working on this issue now for some time as part of my learning curve but am not generating the result I'm after. I would like to know if the approach I'm using is completely wrong or does it just need tweaking. I would appreciate any of your comments and feedback.
The query below generated the output you can see on the at the bottom of this thread. The column are not alligned correctly when pasting into this thread so please copy and paste the output to notepad.
I've also included the result in which I'm after at the bottom of this thread. Can anyone confirm if this is possible using the existing strategy.
QUESTION 1
**********
Is it common for a SQL programmer to then take the result of this query and write a new one or would the programmer generate write the query within another query. Is this a Sub Query.
REQUIREMENT
How can I use the output attached to generate the following information:
A. Group By DOCUMENTNUM_TRIM
B. SUM LT_AMOUNTMST where there is data in DocumentNum_TRIM otherwise do not sum. In this case the data in DOCUMENTNUM_TRIM is 0090969
C. IT_COSTAMOUNTPOSTED where there is data in DocumentNum_TRIM otherwise do not sum. In this case the data in DOCUMENTNUM_TRIM is 0090969
D. take the value from IT_COSTAMOUNTPHYSICAL where VCTCONTRACTTYPEID = Physical
E. There are some records with no DOCUMENTNUM_TRIM but I want them to exist as seperate records within my output. How can this be achieved?
I've also attached the result in which I'm after. Can anyone confirm if this is possible using the existing strategy.
SELECT
LEFT(LT.DOCUMENTNUM,12) AS DOCUMENTNUM_TRIM,
--sum(LT.AMOUNTMST) AS LT_AMOUNTMST
LT.AMOUNTMST AS LT_AMOUNTMST,
(IT.COSTAMOUNTPHYSICAL) AS IT_COSTAMOUNTPHYSICAL,
IT.COSTAMOUNTPOSTED AS IT_COSTAMOUNTPOSTED,
PT.VCTCONTRACTTYPEID
FROM INVENTTRANSPOSTING ITP
INNER JOIN LEDGERTRANS LT ON
ITP.VOUCHER = LT.VOUCHER AND
ITP.TRANSDATE = LT.TRANSDATE
INNER JOIN INVENTTRANS IT ON
IT.INVENTTRANSID = ITP.INVENTTRANSID
LEFT JOIN PURCHTABLE PT ON
PT.PURCHID = IT.TRANSREFID
WHERE
ITP.DATAAREAID = 'CCC'AND
LT.DATAAREAID = 'CCC'AND
LT.ACCOUNTNUM = '9110' AND
ITP.ISPOSTED = '1'
PASTE THIS INTO NOTEPAD (MY EXISTING OUTPUT)
********************************************
DOCUMENTNUM_TRIM LT_AMOUNTMST IT_COSTAMOUNTPHYSICAL IT_COSTAMOUNTPOSTED VCTCONTRACTTYPEID
0090969 2500.00 2500.00 0.00
0090969 1200.00 1200.00 0.00
0090969 999.00 999.00 0.00
0090969 24000.00 28699.00 0.00 Physical
70000.00 98190.00 70000.00 NULL
5000.00 9819.00 5000.00 NULL
PASTE THIS INTO NOTEPAD (WHAT OUTPUT IM AFTER)
**********************************************
OCUMENTNUM_TRIM LT_AMOUNTMST IT_COSTAMOUNTPHYSICAL IT_COSTAMOUNTPOSTED
0090969 28699.00 28699.00 0.00
70000.00 98190.00 70000.00
5000.00 9819.00 5000.00
As you can see I would the records brought through even when DOCUMENTNUM_TRIM is blank.
Thanks and kind regards,
Tomas
The query below generated the output you can see on the at the bottom of this thread. The column are not alligned correctly when pasting into this thread so please copy and paste the output to notepad.
I've also included the result in which I'm after at the bottom of this thread. Can anyone confirm if this is possible using the existing strategy.
QUESTION 1
**********
Is it common for a SQL programmer to then take the result of this query and write a new one or would the programmer generate write the query within another query. Is this a Sub Query.
REQUIREMENT
How can I use the output attached to generate the following information:
A. Group By DOCUMENTNUM_TRIM
B. SUM LT_AMOUNTMST where there is data in DocumentNum_TRIM otherwise do not sum. In this case the data in DOCUMENTNUM_TRIM is 0090969
C. IT_COSTAMOUNTPOSTED where there is data in DocumentNum_TRIM otherwise do not sum. In this case the data in DOCUMENTNUM_TRIM is 0090969
D. take the value from IT_COSTAMOUNTPHYSICAL where VCTCONTRACTTYPEID = Physical
E. There are some records with no DOCUMENTNUM_TRIM but I want them to exist as seperate records within my output. How can this be achieved?
I've also attached the result in which I'm after. Can anyone confirm if this is possible using the existing strategy.
SELECT
LEFT(LT.DOCUMENTNUM,12) AS DOCUMENTNUM_TRIM,
--sum(LT.AMOUNTMST) AS LT_AMOUNTMST
LT.AMOUNTMST AS LT_AMOUNTMST,
(IT.COSTAMOUNTPHYSICAL) AS IT_COSTAMOUNTPHYSICAL,
IT.COSTAMOUNTPOSTED AS IT_COSTAMOUNTPOSTED,
PT.VCTCONTRACTTYPEID
FROM INVENTTRANSPOSTING ITP
INNER JOIN LEDGERTRANS LT ON
ITP.VOUCHER = LT.VOUCHER AND
ITP.TRANSDATE = LT.TRANSDATE
INNER JOIN INVENTTRANS IT ON
IT.INVENTTRANSID = ITP.INVENTTRANSID
LEFT JOIN PURCHTABLE PT ON
PT.PURCHID = IT.TRANSREFID
WHERE
ITP.DATAAREAID = 'CCC'AND
LT.DATAAREAID = 'CCC'AND
LT.ACCOUNTNUM = '9110' AND
ITP.ISPOSTED = '1'
PASTE THIS INTO NOTEPAD (MY EXISTING OUTPUT)
********************************************
DOCUMENTNUM_TRIM LT_AMOUNTMST IT_COSTAMOUNTPHYSICAL IT_COSTAMOUNTPOSTED VCTCONTRACTTYPEID
0090969 2500.00 2500.00 0.00
0090969 1200.00 1200.00 0.00
0090969 999.00 999.00 0.00
0090969 24000.00 28699.00 0.00 Physical
70000.00 98190.00 70000.00 NULL
5000.00 9819.00 5000.00 NULL
PASTE THIS INTO NOTEPAD (WHAT OUTPUT IM AFTER)
**********************************************
OCUMENTNUM_TRIM LT_AMOUNTMST IT_COSTAMOUNTPHYSICAL IT_COSTAMOUNTPOSTED
0090969 28699.00 28699.00 0.00
70000.00 98190.00 70000.00
5000.00 9819.00 5000.00
As you can see I would the records brought through even when DOCUMENTNUM_TRIM is blank.
Thanks and kind regards,
Tomas