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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 replace mName with space

Author  Topic 

gongxia649
So Suave

344 Posts

Posted - 2006-09-21 : 10:01:54
lname fname mname suffix
-------------------------------------------------
POWERS JAMES JAMES D III


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.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-09-21 : 10:05:39
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: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-09-21 : 10:09:39
What have you done so far with coding? Please show us.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-09-21 : 10:11:20
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
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-09-21 : 10:25:20
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
   

- Advertisement -