WebMar 6, 2009 · RTRIM (LTRIM (PARSENAME (REPLACE (full_name, ',', '.'), 1))) AS LastName FROM MyTable; GO You can also use string functions like CHARINDEX, PATINDEX, SUBSTRING, LEFT, RIGHT, RTRIM, LTRIM, ETC. SELECT full_name, LEFT (full_name, CHARINDEX (',', full_name, 1) - 1) AS FirstName, WebJul 24, 2024 · SELECT SUBSTRING (fullname, 1, CHAR INDEX ( ' ', fullname) - 1) AS FirstName, SUBSTRING (fullname, CHAR INDEX ( ' ', fullname) + 1, le n (fullname)) AS LastName FROM YourTable Copy Solution 3 Reverse the problem, add columns to hold the individual pieces and combine them to get the full name.
Reverse order of firstname and lastname in SQL column
WebApr 13, 2024 · Sign In: To view full details, sign in with your My Oracle Support account. Register: Don't have a My Oracle Support account? Click to get started! WebSep 3, 2015 · ALTER TABLE Customer ADD LastName AS RIGHT (FullName, CHARINDEX (' ', REVERSE (FullName)) - 1) PERSISTED This Adds the column LastName to your Customer table, uses the function specified to calculate the value of the last name, and stores it onto the physical table. mass tower shield w101
Split FirstName and LastName from Full Name in SQL
WebMar 27, 2024 · The given SQL statement selects the distinct emp_lname (last name) values from the table named 'emp_details'. That is, it returns a list of unique last names of employees without any duplicates. Relational Algebra Expression: Relational Algebra Tree: Practice Online SELECT DISTINCT emp_lname FROM emp_details; Reset Query … WebAug 8, 2024 · Sign in to vote DECLARE @fullName varchar (50) = 'FirstName LastName'; SELECT LEFT (@fullName, 1) + LEFT (SUBSTRING (@fullName, CHARINDEX (' ', @fullName) + 1, LEN (@fullName)), 1) A Fan of SSIS, SSRS and SSAS Wednesday, August 7, 2024 7:45 PM 0 Sign in to vote Hi Saanah, Please try following script . WebFeb 27, 2024 · SELECT @FirstName = LTRIM (RTRIM (@FirstWord)); SELECT @LastName = LTRIM (RTRIM (@SecondWord)); END END ELSE BEGIN -- There are three words, set First Name and Last Name. -- Title has already been set. mass to volume formula