Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Add records from one table to another
Message
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01652499
Message ID:
01652511
Views:
34
>>>>Yes, there are CHARINDEX and SUBSTRING functions in SQL Server. In SQL Server 2016 (I think) they also finally introduced the split function.
>>>
>>>Thank you.
>>
>>You're welcome. Play with the select statements first until you get it parsed correctly.
>>
>>This blog post may help
>>
>>http://blogs.lessthandot.com/index.php/datamgmt/datadesign/parsing-fullname-field-to-individual/
>
>Thank you. I found this example online and trying to make it work for me:
>
>
>DECLARE @FullName    VARCHAR(50) = 'Mark Zuckerberg'
>
>SELECT SUBSTRING(@FullName, 1, CHARINDEX(' ', @FullName) - 1) AS [First Name],
>       SUBSTRING(@FullName, CHARINDEX(' ', @FullName) + 1, LEN(@FullName)) AS [Last Name]
>
Make sure all odd cases are handled as well (e.g. if you don't have ',' in the name, if you have something extra, NULL, etc.)

>
>They have First Name + Last Name and I have Last Name + Comma + First Name. Give me a couple of hours (:)) and I will figure it out.
>
>Update: I got it:
>
>SELECT SUBSTRING(@FullName, 1, CHARINDEX(', ', @FullName) - 1) AS [Last Name],
>       SUBSTRING(@FullName, CHARINDEX(', ', @FullName) + 1, LEN(@FullName)) AS [First Name]
>
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform