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
 SELECT help

Author  Topic 

godspeedba
Yak Posting Veteran

90 Posts

Posted - 2009-04-20 : 10:01:55
Hello Friends

I have a Select call that needs to grab the name of the country, but only if it is specified. I started with this:

SELECT tb_feature_basket.*, tb_country.country_name, from tb_feature_basket, tb_country
Inner join tb_country on tb_feature_basket.basket_country = tb_country.countryid
WHERE tb_feature_basket.basket_property = @bnbid
and tb_feature_basket.basket_country = tb_country.countryid

The problem I have, if the tb_feature_basket.country is '0' then it won't locate the country_name as there isn't one in the table.

Because of this it won't return any rows. When Ultimately is has to return all the rows and the country name but only if it has one.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-20 : 10:06:17

Try this

SELECT tb_feature_basket.*, tb_country.country_name, from tb_feature_basket, tb_country
left join tb_country on tb_feature_basket.basket_country = tb_country.countryid
and tb_feature_basket.basket_property = @bnbid




Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

godspeedba
Yak Posting Veteran

90 Posts

Posted - 2009-04-20 : 10:18:07
Many thanks Madhivanan, works perfectly.

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-04-20 : 10:20:49
quote:
Originally posted by godspeedba

Many thanks Madhivanan, works perfectly.




You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -