Link to home
Start Free TrialLog in
Avatar of sqlcurious
sqlcuriousFlag for United States of America

asked on

replacing some characters with space

Hi I have a condition where I have to replace the MiddleName  with space that has the following:
'and' 'jr' 'sr' '&*' 'of' anything containing numerics 'R1315', how do I change the below?


SELECT
W.ID,
(CASE when ISNUMERIC(REPLACE(M.MiddleName, ',' , ' '))=1 THEN NULL ELSE MiddleName END)AS [Middle Name],
SOLUTION
Avatar of Snarf0001
Snarf0001
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sqlcurious

ASKER

Hi Snarf0001 thanks, this works for the number part. I just put what u mentioned in a function -HNAI.dbo.Removenumbers
for the rest this is what I Am doing:
(CASE when ISNUMERIC(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(HNAI.dbo.Removenumbers(M.MiddleName),'and',''),'jr',''),'sr',''),'&*',''),'of',''),'^',''),'&',''),'*',''),' ',''))=1 THEN NULL ELSE MiddleName END)AS [Middle Name],

but for some reason I still see 'of' in the results, any idea why it's not going away?
Please close your eyes for a moment.
At that point you will see exactly how much we know about your data :)

Please supply some sample data, and from that data, the result you want.
Id             First Name      Middle Name      Last Name
995959      Estate                            of               Steven      
850018      Dominic                           F                 Meiklejohn
850019      Yolanda                                           Cortese
850020      Ernest                          E                     Craumer
850022      Heidi                         W                     Hamilton
Sorry about that here is the sample data, let's just say I am unable to replace 'of' from the middle name(that's one of the conditions- replace 'of' with a space), let me know if you need more information.Thanks!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If it contains "of" anywhere, are you aiming to null the column itself?
Are you updating the source table or just trying to return the results?

And what if the middle name is "M of D" for example... are we talking about a contains anywhere?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks for your inputs