Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jung1975
Aged Yak Warrior
503 Posts |
Posted - 2004-08-04 : 10:30:20
|
I have a table look likeID Paid_amt Allow_amt Billed_amt 1 400 500 600 1 321 1230 987 1 -400 -500 -600 2 300 300 300 2 500 200 100 2 -500 -200 -100 I would like to find out ID which has the positive amount is equal to negative amount.The return result should looks like:ID Paid_amt Allow_amt Billed_amt 1 400 500 600 1 -400 -500 -600 2 500 200 100 2 -500 -200 -100 |
|
|
raymondpeacock
Constraint Violating Yak Guru
367 Posts |
Posted - 2004-08-04 : 10:34:35
|
| Use the ABS function.SELECT * FROM tablenameWHERE ABS(Paid_amt)=ABS(Allow_Amt)Raymond |
 |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-08-04 : 11:48:52
|
| I don't think that is what he is trying to do in this case...maybe this will help:Drop table #tempTableCreate Table #tempTable (tranId int identity(1,1) not null, id int, Paid_Amt int, Allow_Amt int, Billed_Amt int)Insert Into #tempTableSelect 1, 400, 500, 600 union all Select 1, 321, 1230, 987 union all Select 1, -400, -500, -600Union All Select 2, 300, 300, 300 union all Select 2, 500, 200, 100 union all Select 2, -500, -200, -100Select * From #tempTableSelect A.* From #tempTable as AInner Join #tempTable as BOn A.id = B.idWhere A.Paid_Amt + B.Paid_Amt = 0and A.Allow_Amt + B.Allow_Amt = 0and A.Billed_Amt + B.Billed_Amt = 0Corey |
 |
|
|
raymondpeacock
Constraint Violating Yak Guru
367 Posts |
Posted - 2004-08-04 : 11:56:22
|
| Yeah, you are right - I misunderstood the requirement. To partially save face :) you could still use the ABS function in your code with ABS(a.Paid_Amt) = ABS(b.Paid_Amt), but what you've got would work fine.Raymond |
 |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-08-04 : 11:58:27
|
| hehehe i know the feelingCorey |
 |
|
|
|
|
|
|
|