neel k

neel k

  • NA
  • 143
  • 132.1k

avoid null values in sql query

Nov 25 2014 11:53 AM
hi,
 
This is my query. I need to display the data which is not null. I don't want to display null values. in my database there is only one record with exact city name but it display city which contain null values also. 
 
 
declare
@NAME varchar(2000),
@CITY varchar(250),
@Country varchar(250)
SELECT customer_id,
(coalesce(city, '') + coalesce(', ' + state, '')) as Location ,
(coalesce(address1, '') + coalesce(', ' + address2, '') + coalesce(', ' + address3, '')) as Address
FROM customer LEFT outer JOIN usercountry on usercountry.country_ab = customer.country
left outer JOIN customerstatus on customerstatus.statusId = customer.statusid
Where
1=1
AND (city like '%' + ISNULL(@CITY,city) + '%'  or city is null)
AND user_country.country like '%' + ISNULL(@Country,usercountry.country) + '%'
AND customerstatus.status = 'pending'
 
 
Thank you, 
 
 
 

Answers (3)