Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 replace mName with space
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

So Suave

344 Posts

Posted - 09/21/2006 :  10:01:54  Show Profile  Visit gongxia649's Homepage  Reply with Quote
lname fname mname suffix

update names
set nm_mid = replace(nm_mid, nm_mid, '')
where nm_first = substring(nm_mid, 1, charindex(' ', nm_mid))

i want to replace james with '' on the mname when fname and when the first word on mname are the same. But seems like my code is not working.

Edited by - gongxia649 on 09/21/2006 10:02:49

Cybernetic Yak Master

11752 Posts

Posted - 09/21/2006 :  10:05:39  Show Profile  Visit spirit1's Homepage  Reply with Quote
update names
set nm_mid = replace(nm_mid, substring(nm_mid, 1, charindex(' ', nm_mid)), '')
where nm_first = substring(nm_mid, 1, charindex(' ', nm_mid))

Go with the flow & have fun! Else fight the flow
blog thingie:
Go to Top of Page

Patron Saint of Lost Yaks

30421 Posts

Posted - 09/21/2006 :  10:09:39  Show Profile  Visit SwePeso's Homepage  Reply with Quote
What have you done so far with coding? Please show us.

Peter Larsson
Helsingborg, Sweden

Edited by - SwePeso on 09/21/2006 10:09:56
Go to Top of Page

Dr. Cross Join

7423 Posts

Posted - 09/21/2006 :  10:11:20  Show Profile  Visit jsmith8858's Homepage  Reply with Quote
never write UPDATES like when you are testing things out. Always write it as a SELECT first to get your logic right. Then, only when you have verified that the SELECT does exactly what you want should you run the update itself.

Like usual, you have not explained yourself very well, but I *think* what you want is something this:

set nm_mid = replace(mname, fname, '')

Of course, again, test your formula and your logic with a SELECT to verify things, check all possibilities to make sure they are all covered correctly, and only then should you convert your logic from a SELECT to an UPDATE.

And if what you are trying doesn't work correctly for you, don't just say "it doesn't work", explain to us why .. does it give an error? does it miss some? mess up others? Be specifc. You've been here long enough now to know how this works, right?

- Jeff

Edited by - jsmith8858 on 09/21/2006 10:11:44
Go to Top of Page

Patron Saint of Lost Yaks

30421 Posts

Posted - 09/21/2006 :  10:25:20  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Originally posted by gongxia649

spirit1: sorry, i had my code right. I just was not updating the right table.
peso: Maybe after i finish. Still working very hard on it.

jsmith: I will try to be very more detail specific next time. sorry for the incovinience.

There is no need to post what you have done so far, when you are done. Then it all works and you do not need us to do your work.

Peter Larsson
Helsingborg, Sweden
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000