sql server rtrim everything after character 1

sql server rtrim everything after character

SELECT   [FullName]
	    ,LEFT([FullName], CHARINDEX(',', [FullName]) - 1) AS [Surname]
	    ,REPLACE(SUBSTRING([FullName], CHARINDEX(',', [FullName]), LEN([FullName])), ',', '') AS [FirstName]
FROM    Employee

Here is what the above code is Doing:
1. The LEFT function is used to extract the first part of the string up to the comma.
2. The REPLACE function is used to remove the comma from the second part of the string.
3. The SUBSTRING function is used to extract the second part of the string.
4. The CHARINDEX function is used to find the position of the comma.
5. The LEN function is used to find the length of the string.

Similar Posts