Monday, March 19, 2012

another sql query problem

I have a table like this

DESCRIPTION DEBI CREDIT
-----------
Deposit 0.00 100.00
Withdraw 10.00 0.00
Payroll 0.00 230.00
Withdraw 50.00 0.00

How can i make an query that this table look like this

ID DESCRIPTION DEBI CREDIT Current Balance
------------------
1. Deposit 0.00 100.00 100.00
2. Withdraw 10.00 0.00 90.00
3. Payroll 0.00 230.00 320.00
4. Withdraw 50.00 0.00 270.00

Please helpTry this:

SELECT TOP 100 PERCENT QTest.ID, QTest.Description, QTest.Debit, QTest.Credit, SUM(QTest.Credit) - SUM(QTest.Debit) AS [Current Balance]
FROM QTest,
(SELECT TOP 100 * FROM (SELECT ID, Credit, Debit FROM QTest) QTest_1)
AS QTest_1
WHERE QTest.ID >= QTest_1.ID
GROUP BY QTest.ID, QTest.Description, QTest.Debit, QTest.Credit
ORDER BY QTest.ID

where QTest is yout table

Originally posted by bashka_abdyli
I have a table like this

DESCRIPTION DEBI CREDIT
-----------
Deposit 0.00 100.00
Withdraw 10.00 0.00
Payroll 0.00 230.00
Withdraw 50.00 0.00

How can i make an query that this table look like this

ID DESCRIPTION DEBI CREDIT Current Balance
------------------
1. Deposit 0.00 100.00 100.00
2. Withdraw 10.00 0.00 90.00
3. Payroll 0.00 230.00 320.00
4. Withdraw 50.00 0.00 270.00

Please help

No comments:

Post a Comment