Technical Article

Get full name of a person

,

Person name may have these combination in database
1. firstname only
2. middlename only
3. lastname only
4. firstname + middlename
5. firstname + lastname
6. middlename + lastname
And firstname, middlename, lastname may contain null or empty string in data. but usee want to display Fullname without spaces then how will combine all.

CREATE  FUNCTION GetFullName(
@fName nvarchar(256), 
@mName nvarchar(256),
@lName nvarchar(256))
  
RETURNS nvarchar(768) AS  
BEGIN 
DECLARE @fullName nvarchar(768)
SELECT @fullName = LTRIM(RTRIM(LTRIM(@fName))+RTRIM(' '+LTRIM(ISNULL(@mName,'')))+RTRIM(' '+LTRIM(@lName)))
return @fullName
END

Rate

1 (1)

You rated this post out of 5. Change rating

Share

Share

Rate

1 (1)

You rated this post out of 5. Change rating