Tuesday, December 10, 2013

How to find first name,Middle name,last name in sql

SELECT
LEFT(transaction_claimant_Firstname,CHARINDEX('|',transaction_claimant_Firstname + '|')-1) AS FirstName,
CASE WHEN LEN(transaction_claimant_Firstname) - LEN(REPLACE(transaction_claimant_Firstname,'|','')) > 1  THEN PARSENAME(REPLACE(transaction_claimant_Firstname,'|','.'),2) ELSE NULL END AS MiddleName,
CASE WHEN LEN(transaction_claimant_Firstname) - LEN(REPLACE(transaction_claimant_Firstname,'|','')) > 0 THEN PARSENAME(REPLACE(transaction_claimant_Firstname,'|','.'),1) ELSE NULL END AS LastName
FROM tablename

No comments:

Post a Comment