Hi Everyone
I am busy converting access queries for sql server but i dont understand why this one wont work..
SELECT
(T1.Debit) As Debit,
(T1.Credit) As Credit,
(T1.Debit - T1.Credit) As Balance,
T1.CustCode
FROM
(
SELECT
SUM(AverageDebit) As Debit,
SUM(AverageCredit) As Credit,
CustCode
FROM
(
SELECT
(IIF(TransactionType IN (0,
6,
9,
10,
11,
14,
16,
17,
18,
19,
21),
ABS(Price1) ,
0)) AS AverageDebit,
(IIF(TransactionType IN (1,
2,
3,
7,
15,
22),
ABS(Price1),
0)) AS AverageCredit,
CustCode,
TransactionType
FROM
TransactionHeader
WHERE
CustCode = 'AA0001'
GROUP BY
CustCode,
TransactionType,
Price1,
ID)
GROUP BY
CustCode) As T1
Any suggestions what is wrong with this query ?
Thanks
What I have tried:
Removing Group by,
tried a few other modifications ,
I tried the following and it works , dont know if its the same as the access one tho
SELECT
(T1.Debit) As Debit,
(T1.Credit) As Credit,
(T1.Debit - T1.Credit) As Balance,
T1.CustCode
FROM
(
SELECT
SUM(AverageDebit) As Debit,
SUM(AverageCredit) As Credit,
CustCode
FROM
(
SELECT
(IIF(TransactionType IN (0,
6,
9,
10,
11,
14,
16,
17,
18,
19,
21),
ABS(Price1) ,
0)) AS AverageDebit,
(IIF(TransactionType IN (1,
2,
3,
7,
15,
22),
ABS(Price1),
0)) AS AverageCredit,
CustCode,
TransactionType
FROM
TransactionHeader
WHERE
CustCode = 'AA0001'
GROUP BY
CustCode,TransactionType,Price1
)AS TS2 GROUP BY TS2.CustCode ) As T1