SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 If Null, use a different text
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

richardlaw
Yak Posting Veteran

United Kingdom
68 Posts

Posted - 10/14/2012 :  15:26:31  Show Profile  Visit richardlaw's Homepage  Reply with Quote
Hi

I've created a view which I'm using for a drop down menu in a web application. In my drop down menu, I've built up a collection of columns to make one view column which I use as part of the drop down menu. It all works fine, until on of the columns in the group is Null.

Here is an example extract from the select statement from the view:


dbo.tbl_Locations.Location_Value + ': ' + dbo.tbl_Weekdays.Weekday_Short + ' ' + PARSENAME(RIGHT (REPLACE(CONVERT (VARCHAR(26), dbo.tbl_Classes.Class_TimeFrom, 100), ' ', '.'), 7), 1) + ' - ' + PARSENAME(RIGHT (REPLACE(CONVERT (VARCHAR(26), dbo.tbl_Classes.Class_TimeTo, 100), ' ', '.'), 7), 1) + ' (' + dbo.tbl_Disciplines.Discipline_Value + ' with ' + dbo.tbl_Members.Member_FirstName AS ClassInfo


In this case, if 'dbo.tbl_Members.Member_FirstName' is NULL, the whole block is null.

Is there a way that as part of the view select statement I can include the Member_FirstName, but if it's NULL, replace with 'No Coach assigned'?

Thanks as alwasy

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 10/14/2012 :  15:52:27  Show Profile  Reply with Quote
Use COALESCE or ISNULL function for each of the columns that may/can contain NULLs. For example:
COALESCE(dbo.tbl_Locations.Location_Value,'') + ': ' + COALESCE(dbo.tbl_Weekdays.Weekday_Short,'') + ' ' +

or perhaps
COALESCE(dbo.tbl_Locations.Location_Value,'DefaultLocation') + ': ' + COALESCE(dbo.tbl_Weekdays.Weekday_Short,'DefaultWeekday') + ' ' +

Edited by - sunitabeck on 10/14/2012 15:53:04
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.17 seconds. Powered By: Snitz Forums 2000