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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 a join

Author  Topic 

cwtriguns2002
Constraint Violating Yak Guru

272 Posts

Posted - 2007-06-22 : 03:14:22
Hi...probs in joining...

table1 - hrEmpLoans
pkeyno amount fixdeduc interest
1 1000 500 100
2 2000 400 100
3 3000 300 100
4 4000 200 100
5 5000 100 100

table2 - hrEmpLoanPayments
fkeyno total_payment
3 2500
4 2000


My expected result is:
pkeyno balance
1 1000
2 2000
3 500
4 2000
5 5000

-Thanks

-Ron-

"A logician trying to explain logic to a programmer is like a cat trying to explain to a fish what it's like to get wet."

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-06-22 : 03:18:30
[code]SELECT l.pkeyno, amount = l.amount - ISNULL(p.total_payment, 0)
FROM hrEmpLoans l LEFT JOIN hrEmpLoanPayments p
ON l.pkeyno = p.fkeyno[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

cwtriguns2002
Constraint Violating Yak Guru

272 Posts

Posted - 2007-06-22 : 03:20:30
ok thanks KH. left join is the solutionto my problem.

-Ron-

"A logician trying to explain logic to a programmer is like a cat trying to explain to a fish what it's like to get wet."
Go to Top of Page
   

- Advertisement -