Justinidea
Board Regular
- Joined
- Apr 7, 2010
- Messages
- 57
I have a Database that looks like this:
Before
<tbody>
</tbody>
I have three queries to delete the rows with negative values so that the table looks like this
After
<tbody>
</tbody>
I'm wondering if there is a way to do this with only one query.
Here are the three I use, is there anyway to merge these three in to a single query?
Before
[A].NAME, | [A].GROUP_CODE, | [A].ENTITLED_AMT, | A].PTY_TRN_UID, | [A].SumOfEntAmt |
Jim | NAN | -26.20 | J301 | -218.5 |
Jim | NAN | 26.20 | J302 | 218.5 |
Jim | NAN | -75.20 | J301 | -218.5 |
Jim | NAN | 75.20 | J302 | 218.5 |
Jim | NAN | -80.10 | J301 | -218.5 |
Jim | NAN | 80.10 | J302 | 218.5 |
Jim | NAN | -37.00 | J301 | -218.5 |
Jim | NAN | 37.00 | J302 | 218.5 |
<tbody>
</tbody>
I have three queries to delete the rows with negative values so that the table looks like this
After
[A].NAME, | [A].GROUP_CODE, | [A].ENTITLED_AMT, | [A].PTY_TRN_UID, | [A].SumOfEntAmt |
Jim | NAN | 26.20 | J302 | 218.5 |
Jim | NAN | 75.20 | J302 | 218.5 |
Jim | NAN | 80.10 | J302 | 218.5 |
Jim | NAN | 37.00 | J302 | 218.5 |
<tbody>
</tbody>
I'm wondering if there is a way to do this with only one query.
Here are the three I use, is there anyway to merge these three in to a single query?
Code:
[U]Query 1[/U]
SELECT [A].PTY_TRN_UID,
Sum([A].ENTITLED_AMT) AS SumOfENTAMT INTO [B]
FROM [A]
GROUP BY [A].PTY_TRN_UID
[U]Query 2[/U]
UPDATE [A] INNER JOIN [B]
ON [A].PTY_TRN_UID = [B].PTY_TRN_UID
SET [A].SumOfEntAmt = [B]![SumOfEntAMT]
[U]Query 3[/U]
DELETE DISTINCTROW
[A].NAME,
[A].GROUP_CODE,
[A].ENTITLED_AMT,
[A].PTY_TRN_UID,
[A].SumOfEntAmt
FROM [A]
WHERE [A].SumOfEntAmt)<0;
Last edited: