lrdchelp
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
Can someone help with the code?
Thanks.
Shari
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
When I tried again, I received a message that it is not a valid set option.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
UPDATE tablename
SET lastname = 'Dr. ' + lastname
SET lastname = 'Dr. ' + lastname
UPDATE your_tablename
SET
Group_Dept_Name = 'Dr. ' + LastName
WHERE
LastName IS NOT NULL AND
LastName NOT LIKE 'Dr.%'
--AND ...other conditions...
SET
Group_Dept_Name = 'Dr. ' + LastName
WHERE
LastName IS NOT NULL AND
LastName NOT LIKE 'Dr.%'
--AND ...other conditions...
ASKER
My query was:
set Group_Dept_Name = 'Dr. ' + LastName