January 23, 2013 at 2:55 am
Hi Team,
I have below query:
SELECT lname +'.' +fname AS emp_name FROM employees
Result : First_Name.Last_Name
If any one (lname or fname is NULL, then result is showing as NULL)
My requirement is :
If lname is NULL then result should be fname (without dot(.))
If fname is NULL then result should be lname (should not end with dot(.))
Please help
January 23, 2013 at 3:15 am
Use a CASE expression.
John
January 23, 2013 at 3:16 am
pls use below code...
declare @t1 table(fname varchar(50),lname varchar(20))
insert into @t1(fname,lname) values('sql','server')
insert into @t1(fname) values('ravi')
insert into @t1(lname) values('kumar')
select *,case when (fname is not null) and (lname is not null) then fname+'.'+lname
else isnull(fname,lname)
end from @t1
January 23, 2013 at 3:21 am
Thank u Subba Reddy.
May i know Where r u from.
January 23, 2013 at 3:33 am
Hi,
I want result column name should be "Employee_Name"
select *,case when (fname is not null) and (lname is not null) then fname+'.'+lname
AS employee_Name
else isnull(fname,lname)
It is not working,
Can u please help...
January 23, 2013 at 3:35 am
select *,case when (fname is not null) and (lname is not null) then fname+'.'+lname
else isnull(fname,lname)
end AS employee_Name
January 23, 2013 at 7:12 am
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply