|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Friday, May 10, 2013 6:46 AM
Points: 86,
Visits: 145
|
|
I could really use some help on this one. I am trying to select the Company column if it has a value or fname + lastname if it does not. Here is what I am thinking, I know this doesn't work.
SELECT [ID] ,[Title] ,[fname] ,[lastname] ,[Company] ,[Attention] ,if(Company != null or Company != '') [Company] as displayName else fname + ' ' + lastname as displayName FROM [Donors]
Any help, guidence or other constructive comments would be greatly appreciated.
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: 2 days ago @ 1:45 PM
Points: 15,442,
Visits: 9,572
|
|
You're on the right track, but what you need is "Case When Else". Look up Case in Books Online, it's got samples, syntax, etc.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Monday, April 30, 2012 9:22 AM
Points: 138,
Visits: 68
|
|
Hey,
find the following soln...
SELECT [ID] ,[Title] ,[fname] ,[lastname] ,[Company] ,[Attention] , case when (Company is not null or len(Company) <> 0) then [Company] else fname + ' ' + lastname end as displayName FROM [Donors]
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Friday, May 10, 2013 6:46 AM
Points: 86,
Visits: 145
|
|
| Thank you very much that was exactly what I needed to fix it up. You rock
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Wednesday, July 11, 2012 6:35 AM
Points: 329,
Visits: 194
|
|
sreddy (4/13/2009) Hey,
find the following soln...
SELECT [ID] ,[Title] ,[fname] ,[lastname] ,[Company] ,[Attention] , case when (Company is not null or len(Company) <> 0) then [Company] else fname + ' ' + lastname end as displayName FROM [Donors]
Try this too.
SELECT [ID] ,[Title] ,[fname] ,[lastname] ,[Company] ,[Attention] , IsNull( NullIf(Company, ''),fname+' '+ lastname) as displayname FROM [Donors]
Regards Vinay
|
|
|
|