cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

profit and loss statement sql

Former Member
0 Likes
2,131

i have a sql anywhere database which have 3 table

(1)  accounttype
----------------
catid    smallint
catname   varchar (20)
----------------------------
data values
catid    catname    
1      Expenditure
2       Income
3       Assets
4       Liabilities
-----------------------------
(2)  accounts
-------------
code integer
name varchar(30)
type smallint
-----------------------
type column has foreign key to  catid from accounttype table
---------------------------
data values
code    name                  type
712001  General expenses    1
712002  Rent account    1
712003  Salaries Account    1
711001  Purchases   1
711002  Purchases return    1
811001  Sales Account   2
811002  Sales Return    2
411001  Furniture account   3
632001  Bank Account    3
642001  Bills receiable 3
631001  Cash Account    3
222001  Bill Payable    4
221020  Jayaram Bros    4
110001  Capital Account 4
=========================
(3)  voucher
-----------
vno        integer
debit      integer
vdate     date
amount  numeric(15, 2)
credit     integer 
debit and credit column has foreign key to code from accounts table
vno debit   vdate        amount             credit
1   631001  01-04-2018     500000.00      110001
2   632001  01-04-2018     400000.00      631001
3   711001  02-04-2018      150000.00     632001
4   712002  02-04-2018       9000.00       632001
6   711001  03-04-2018       50000.00      631001
7   711001  05-04-2018       250000.00    221020
8   631001  06-04-2018      45000.00       811001
9   711002  10-04-2018      15000.00      221020
10  221020  19-04-2018       235000.00   222001
11  811002  21-04-2018       5000.00       632001
12  411001  28-04-2018      45000.00     632001
13  411001  29-04-2018      35000.00     711001
14  712001  30-04-2018       9000.00      632001
15  712001  30-04-2018       5500.00      632001

sir, i want to generate profit and loss statement from the above tables i am facing difficulties to generate the sql for the profit and loss statement Does anybody know how to get the profit and loss statement?

regards kumar

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Likes

thanks for the response this is the sql code I tried, but it doesn't gives the correct order SELECT "vouchers"."debit",
SUM("vouchers"."amount" ),
"vouchers"."credit",
"accounts"."code",
"accounts"."type"
FROM "accounts",
"vouchers"
WHERE ( "vouchers"."debit" = "accounts"."code" ) and
( ( "accounts"."type" = :typ ) OR ( "accounts"."type" = :typo ) )
Group by "vouchers"."debit", "vouchers"."credit", "accounts"."code", "accounts"."type"

please anybody have a solution, it will be helpful

regards kumar