Link to home
Start Free TrialLog in
Avatar of lrdchelp
lrdchelpFlag for United States of America

asked on

Help needed with sql code

I have a table in a sql database that has the last name of every member of a group.  I want to add the word "Dr." to the front of each last name.  I am looking for something similar to a search/replace function.

Can someone help with the code?

Thanks.
Shari
SOLUTION
Avatar of sameer_goyal
sameer_goyal
Flag of India 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 lrdchelp

ASKER

I tried that but get an incorrect syntax message near the '='
My query was:
set Group_Dept_Name = 'Dr. ' + LastName
I see my mistake. I forgot to substitute for LastName.

When I tried again, I received a message that it is not a valid set option.
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
UPDATE tablename
SET lastname = 'Dr. ' + lastname
Avatar of Scott Pletcher
UPDATE your_tablename
SET
    Group_Dept_Name = 'Dr. ' + LastName
WHERE
    LastName IS NOT NULL AND
    LastName NOT LIKE 'Dr.%'
    --AND ...other conditions...