I want to find the space between First Name and Last Name in SQL Server or First Name and Middle Name. I am aware of space function, but not sure if we can use it to find the space between two words. My table has around one million rows in the table. One of the columns is customerName. First Name, Middle Name and Last Name are stored as a combined name in the same row so for e.g.
Steven Ramirez is stored in the CustomerName column. Below is my table
CREATE TABLE [dbo].[CustomerData](
[ID] [int] IDENTITY(1,1) NOT NULL,
[CustomerName] [varchar](500) NULL
) ON [PRIMARY]
GO
These are the names in the table:
INSERT INTO [dbo].[CustomerData]
([CustomerName])
VALUES
('Steven Ramirez')
GO
INSERT INTO [dbo].[CustomerData]
([CustomerName])
VALUES
('Steven Middle Ramirez')
go
INSERT INTO [dbo].[CustomerData]
([CustomerName])
VALUES
('Steven Ramirez')
I want to find the space between First Name and Last Name and also First Name and Middle Name in SQL Server. So for all the rows, I should get
4
4
3
because there are 4 spaces between steven and Ramirez and there are 4 spaces between Steven and Middle and 3 spaces between steven and Ramirez
Steven Ramirez --4
Steven Middle Ramirez--4
Steven Ramirez--3
So I just want to return
4
4
3