How to split Name into First name, Middle Name and Last Name in SQL Server

Data migration is often headache process. Some old systems stores “FullName” in a single column.But the most efficient technique is to store full name into FirstName, MiddleName and LastName columns. And for this we need to split Name into First name, Middle Name and Last Name in SQL Server.

We can use different functions like CHARINDEX, SUBSTRING. Still again issue is that every unique system has its own way.

Last Split Function in SQL Server  got lots of page views and shared by many on Stackoverflow, MSDN.  I created below table valued function to split Name into First name, Middle Name and Last Name.

After creating function, I checked few examples that how can I parse first, middle and last name from fullname field.

 

Below are results of SELECT statements.

 

t-Name-into-firstname-middlename-lastname

Let me know your thoughts, suggestions or any improvements on functions.  I hope you enjoy this function.

Cursor in SQL Server

ursor-example-in-SQL-server Cursor in SQL Server is a control structure which process data row by row. It enables rows in a result to process sequentially. SQL Cursor is a type of iterator which can be used to process any record of table & can modify records according to our needs. To use cursors in SQL procedures, you […] Continue Reading →

How to Delete Duplicate Rows in SQL Server

User-Table-with-sample-data In earlier post, I published article about Find duplicate rows in SQL. Now It’s easy when you have small amount of duplicate data. But in million records,it’s very difficult to delete duplicate rows in SQL. Continue with older post, I have added one more duplicate Email.My table will look like below.! Now what I want is, […] Continue Reading →

SQL Order by string And Number

order-by-string-and-number Order By clause is used to order a number or string of any column of SQL. We can esaily order any column if it;s data-type is INTEGER.Suppose we have column contain data like 2A,1,4,3B,11,111 in VARCHAR column and need to order this column.So below SQL tutorial is about Order by String and number in SQL […] Continue Reading →

How to block IP Address from website

block-IP-address Many times we want to block IP Address so particular machine is not able to access website/blog again. People may be hackers,enemies,Invalid clickers or may be another.Below is guide to block IP address from website. Login to Cpanel Account Almost all Hosting providers offers you cPanel.Login to your cPanel,for my example I use BlueHost here. Go to […] Continue Reading →

Date Functions in SQL Server with Examples

Date-functions-in-SQL-server As a good programmer,you need to use many Date functions in SQL Server.I share here most used Date functions of SQL Server which will do different functionality according to its needs. GETDATE() You can easily retrieve current Date Time in SQL Server using GETDATE() function. Query : select GETDATE() CONVERT() Many times,We want to convert Date Format […] Continue Reading →

How to write- create Stored Procedure in SQL Server

A stored procedure is a group of Transact-SQL statements compiled into a single execution plan.(Source: MSDN).To create stored procedure in SQL Server,Go to Database ->Programmability->Stored Procedures.Click right click and click on New Stored Procedure.It will create a new Query Window for you. You will get above image script in your SQL Server.In this script,you have to […] Continue Reading →

Get comma separated values in SQL Server

comma-separated-values-in-SQL-server Many times,We want to covert rows of SQL table into comma separated string which works as value.You can get comma separated values in SQL Server using COALESCE function or without it. I hope you have created table,otherwise in my example check Case Statement in SQL Server for to create & insert scripts for Product Table. After creating Product […] Continue Reading →