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 2000 Forums
 SQL Server Development (2000)
 Need help with select statement

Author  Topic 

ppuar
Starting Member

28 Posts

Posted - 2002-11-12 : 13:53:45
Here is my code I am having problems with:

select iIndividualId,

(select chRegionName
from region
where chRegionCode = i.chRegionCode
and chCountryCode = i.chCountryCode)

from individual as i
where i.iIndividualId = 22222222

When I run this query with region code blank and country code with 'CA', then I should get no results back. However, instead of returning blank it returns null. The problem is that I don't NULL.

I have also tried the following with no sucess:

(select isnull(chRegionName, '')
from region
where chRegionCode = i.chRegionCode
and chCountryCode = i.chCountryCode)

from individual as i
where i.iIndividualId = 22222222

Does anyone know what I am doing wrong?

Thanks
Pardeep

motokevin
Starting Member

36 Posts

Posted - 2002-11-12 : 14:01:01
Try This:

SELECT i.IndividualID, ISNULL(r.chRegionName, '')
FROM Individual i
LEFT OUTER JOIN Region r On (i.chRegionCode = r.chRegionCode AND i.chCountryCode = r.chCountryCode)
WHERE i.IndividualID = 22222222

Go to Top of Page

ppuar
Starting Member

28 Posts

Posted - 2002-11-12 : 14:09:39
Thanks it worked

Go to Top of Page
   

- Advertisement -