Link to home
Start Free TrialLog in
Avatar of JCWEBHOST
JCWEBHOST

asked on

Sql Null

Hey guys, i have a question.

i have an sql query

select DISTINCT UPPER(r_name) as r_name, UPPER(address) as address, area, location, p_code, tel, website, '<b>'+ r_name + '</b>' + '<br>' + address + '<br>' + area + '<br>' + location + '<br> Contact: ' + tel  as InfoWindowText, Latitude as Lat, Longitude as Lng FROM dbo.pretoria where active='Yes'


my problem is here

'<b>'+ r_name + '</b>' + '<br>' + address + '<br>' + area + '<br>' + location + '<br> Contact: ' + tel  as InfoWindowText

if my location is null it not pulling

so how can i have an if statement in that query so if loction is null it must not add the location and if it is not null add the loction to the nfoWindowText?

ASKER CERTIFIED SOLUTION
Avatar of John_Arifin
John_Arifin
Flag of Indonesia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of gplana
gplana
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi
You can use ISNULL() function to check whether the location field is null or not. SQL query is pasted below:
select 
		DISTINCT UPPER(r_name) as r_name, 
		UPPER(address) as address, 
		area, 
		location, 
		p_code, 
		tel, 
		website, 
		'<b>'+ r_name + '</b>' + '<br>' + [address] + '<br>' + area + '<br>' + ISNULL(location,'') + '<br> Contact: ' + tel as InfoWindowText,
		Latitude as Lat, 
		Longitude as Lng
	FROM dbo.pretoria 
		 where active='Yes'

Open in new window