Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hello guys!I'm in a bit of a dilemma here. here is a table structure:OID-FirstName-LastName-FullName2---NULL------NULL-----Ifty Khan3---NULL------NULL-----JASON JONES4---NULL------NULL-----Mike Hackett (pharm)The column was being used and new requirements demand a FirstName and LastName instead of FullName. FullName stays for backward compatibility but I need to fill in the FirstName and LastName from FullName based on the space in FullName.Any help will be greatly appreciated
Sachin.Nand
2937 Posts
Posted - 2010-11-03 : 08:34:30
Will the word before the first space always be considered as firstname?PBUH
HassanGulzar
Starting Member
4 Posts
Posted - 2010-11-03 : 08:38:24
Yup. Anything until the first ' ' is encountered is a FirstName
HassanGulzar
Starting Member
4 Posts
Posted - 2010-11-03 : 08:47:33
I have this so far:
SELECT Manager.OID , Manager.FullName , LEFT(Manager.FullName, patindex('%[ ' + char(8) + ']%', Manager.FullName) - 1) AS FirstName --, RIGHT(Manager.FullName, CHARINDEX(CHAR(8), REVERSE(Manager.FullName)) - 1) AS LastNameFROM Manager ORDER by Manager.OID
It dies after a while once it hits a FullName without any space character like: "hassan" or "n/a"