Click here to Skip to main content
15,906,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hii,
CASE (Select FirstName + ' ' + LastName from Employee where Id = p.MeetingWith) WHEN '' THEN 'manager(tbs)' END AS ManagerName

this is my one column i am retriving in storeprocedure... what i want to do is .. if my coming column name is NULL or blank then i want to show manager name as "manager(tbs)" else i want to display coming result of manager name
Posted

Actually, you can just use COALESCE().

Try

SQL
SELECT COALESCE(FirstName + ' ' + LastName, 'manager(tbs)') AS ManagerName
FROM Employee
WHERE id = p.MeetingWith


COALESCE will return the first NON NULL value it finds. So, if FirstName and LastName IS NULL then you will get 'manager(tbs)'
 
Share this answer
 
Hi,

All you need to do is to nest the case statements as follows:

SQL
Case when CASE (Select FirstName + ' ' + LastName from Employee where Id = p.MeetingWith) WHEN '' THEN 'manager(tbs)' END is null then 'manager(tbs)' when CASE (Select FirstName + ' ' + LastName from Employee where Id = p.MeetingWith) WHEN '' THEN 'manager(tbs)' END='' then 'manager(tbs)' else CASE (Select FirstName + ' ' + LastName from Employee where Id = p.MeetingWith) WHEN '' THEN 'manager(tbs)' END end as manager
 
Share this answer
 
Comments
Torakami 26-Jul-13 10:03am    
why you checked for two times in this i didnt get this
milenalukic 26-Jul-13 10:06am    
Once for null and the second time for blank

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900