Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Add records from one table to another
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01652499
Message ID:
01652511
Vues:
35
>>>>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform