Click here to Skip to main content
15,905,967 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have a UDF([Name_Parser]) that accepts a name
('Mrs. Thurston Howell, IV' and returns the following

original: Mrs. Thurston Howell, IV
prefix: Mrs
firstName: Thurston
middleName:
lastName: Howell
suffix: IV


So the UDF is working fine.

---------------------------------------------------
DECLARE @TNAME  varchar(50)
    SET @TNAME = 'Mrs. Thurston Howell, IV'

SELECT * INTO #TempVariable1 
FROM [dbo].[Name_Parser](@TNAME)


SELECT  
   original ( Full Name Field )
 , prefix
 , firstName
 , middleName
 , lastName
 , suffix
  FROM #TempVariable1

---------------------------------------------------

What I need to do is Perform an update on the User Table and take the Name data and pass it to the UDF, get the results and update the different fields and complete the update.

Any ideas on how this can be done?

What I have tried:

Everything that I can think of.

UPDATE dbo.USER
SET First_Name = firstName
SET Last_Name  = lastName


I just do not know how to make this work.
Any constructive help would be greatly appreciated.
Posted

1 solution

Something like this should work:
SQL
UPDATE
    U
SET
    First_Name = P.firstName,
    Last_Name = P.lastName
FROM
    dbo.[USER] As U
    CROSS APPLY dbo.Name_Parser(U.Full_Name) As P
;

However, you should probably read Falsehoods Programmers Believe About Names[^] first. :)
 
Share this answer
 
Comments
[no name] 9-Apr-24 2:23am    
Thank you so much for this response Richard, It worked just the way you coded it.

Many Many Many Thanks

Mark Moss
Maciej Los 9-Apr-24 11:41am    
+5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900