I have a question about querying accounting data.
For example, the sample data is show like below
Table: Table_Test
Date Amount
2013-01-01 12.00
2013-01-02 13.00
The output should be like this:
Date Account Debit Credit
2013-01-01 Abccompany 12.00
2013-01-01 Vendorcompany 12.00
2013-01-02 Abccompany 13.00
2013-01-02 Vendorcompany 13.00
Initially, I was think about using a union statement because may be the output sequece is not very important and the sample sql show like below
Select
Date as 'Date',
'Abccompany' as 'Account',
Amount as 'Debit',
'0' as credit
from Table_Test
union
select
Date as 'Date',
'VendorCompany' as 'Account',
'0' as 'Debit',
Amount as credit
from Table_Test
Output:
Date Account Debit Credit
2013-01-01 Abccompany 12.00
2013-01-02 Abccompany 13.00
2013-01-01 Vendorcompany 12.00
2013-01-02 Vendorcompany 13.00
but it seem after I show the output to my PIC, he mention it was wrong that the sequence is quite important to them.(used to export into their system)
What came out from my mind is using T-Sql to manipulate this that may be provide a flag like IsDebit and possible row_number(odd number in first sql, even number on second sql then union and made some logic on it? Possible?)
Is someone are able to provide me some idea how to deal with this?