Solved

Can't see the forest for the trees

Posted on 2012-03-20
5
230 Views
Last Modified: 2012-03-21
I have the following table (3500 rows)

Some (most) first name fields also contain middle name or initial


Last Name        First Name                          Middle Name                       Address 1
Peone               Nicholas Kane                            NULL                                      1435 Emma Lane
Russo               Joseph J.                                    NULL                                       347 6th Ave., #3
McDonnell      Sarah Wimsatt                            NULL                                       180 L St., #2
Carvalho              Michael Paul                            NULL                                      2168 Major Loring Way
Gildea              Caitlin                                   Elizabeth                              549 Columbus Ave., #4
Lowe              Justin J.                                   NULL                                     AGO-CPD
Welch             William M.                           NULL                                     25 Meadowbrook Rd.
Adams             Sandra                                   NULL      57 Fitchburg Rd.


I am trying to extract the middle name/initial an stuff it into the middle name field.

Once I know that is correct I'll truncate first name at the space

This is the code I am using



       update newlawyers2011
            set middle_name = substring(first_name,
                  (select patindex('% %',rtrim(first_name))) + 1,
                  len(rtrim(first_name))
      where (select patindex('% %',rtrim(first_name)) > 0

Fails with error-

Server: Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'where'.
Server: Msg 170, Level 15, State 1, Line 3
Line 3: Incorrect syntax near '>'.


I have been staring at this for 2 hours and I can't read the letters any more.
Any help would be appreciated
0
Comment
Question by:Jeff_Kingston
  • 2
  • 2
5 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 500 total points
ID: 37744385
Do This:-

update newlawyers2011 set middle_name =
substring(first_name,patindex('% %',rtrim(first_name)) + 1,len(rtrim(first_name))
where (patindex('% %',rtrim(first_name)) > 0
0
 

Author Comment

by:Jeff_Kingston
ID: 37744416
Now get this error


Server: Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'where'.
0
 
LVL 25

Expert Comment

by:TempDBA
ID: 37744487
Little modification to BuggyCoder solution

update newlawyers2011 set middle_name =
substring(first_name,patindex('% %',rtrim(first_name)) + 1,len(rtrim(first_name))
where (patindex('% %',rtrim(first_name))) > 0
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37744550
Thanks TempDBA i generally mess up with braces...
You are a life saver....
:-)
0
 

Author Closing Comment

by:Jeff_Kingston
ID: 37747341
Thanks saved the day
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now