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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Query Help regarding Joins? - RESOLVED

Author  Topic 

Mits
Starting Member

48 Posts

Posted - 2007-03-10 : 09:38:19
Hello everyone

I have 2 tables as follows

Invoicedata ----------------------InvoicePayment
[Invoice No]----------------------[Invoice No]
[Customer Id]---------------------[Amount Paid]



I want to get all the records from Invoice data based on Customer Id and if the same [Invoice no] exists in InvoicePayment then it should return [Amount Paid] otherwise 0.0.

I know its not very complicated but, I just cant think straight today.


Any help would be nice



Mitesh



jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-03-10 : 10:02:01
something like this?


select
id.[Invoice No]
id.[Customer Id]
,coalesce(ip.[Amount Paid], 0.0)
from
InvoiceData id
left join
InvoicePayment ip on ip.[Invoice No] = id.[Invoice No]



EDIT: your life would be easier if you didn't put spaces in object/column names...


www.elsasoft.org
Go to Top of Page

Mits
Starting Member

48 Posts

Posted - 2007-03-10 : 10:38:11
hi jezemine
your solution is spot on. Thanks a lot.

Mitesh
Go to Top of Page
   

- Advertisement -