It is very common that sometime you will need to split a Fullname column into FirstName and Lastname columns, to do that you just need these functions:
GetFirstName
CREATE FUNCTION [dbo].[ufn_GetFirstName] ( @FullName varchar(500) ) RETURNS varchar(500) AS BEGIN -- Declare the return variable here DECLARE @RetName varchar(500) SET @FullName = replace( replace( replace( replace( @FullName, '.', '' ), 'Mrs', '' ), 'Ms', '' ), 'Mr', '' ) SELECT @RetName = CASE WHEN charindex( ' ', ltrim( rtrim( @FullName ) ) ) > 0 THEN left( ltrim( rtrim( @FullName ) ), charindex( ' ', ltrim( rtrim( @FullName ) ) ) - 1 ) ELSE '' END RETURN @RetName END
Continue reading “Get Firstname and Lastname from Fullname” »