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 2008 Forums
 Transact-SQL (2008)
 SQL Join on Condition

Author  Topic 

cdnapps
Starting Member

1 Post

Posted - 2010-08-28 : 17:28:21
I have a table called Leaves. Fields are,

* LeaveID
* PersonID
* ActingPersonID

In Person's table, I have,

* PersonalID
* EmployeeCode
* PersonName

Now, in the datagrid, I need to show,

* PersonEmployeeCode
* PersonName
* ActingPersonEmployeeCode
* ActingPersonName

Now, I know how to write the SQL Join to get the data populated. But, the problem is, in some cases, there won't be any acting person. In which case, I need to display data,

* PersonEmployeeCode = 0001
* PersonName = John
* ActingPersonEmployeeCode = -
* ActingPersonName = No acting Person

Now, I am stuck here. How do I do a conditional join statement?

I really need a quick help on this...

Regards

Kush

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-08-28 : 18:51:03
LEFT JOIN will return NULL if there is no matching record.
So you can use ISNULL() or COALESCE().


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -