• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 744
  • Last Modified:

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
0
lrdchelp
Asked:
lrdchelp
2 Solutions
 
sameer_goyalCommented:
Considering your table has a column naming 'LastName', you can you do this

Update tablename
set LastName = 'Dr. ' + LastName

You should be done
0
 
lrdchelpAuthor Commented:
I tried that but get an incorrect syntax message near the '='
My query was:
set Group_Dept_Name = 'Dr. ' + LastName
0
 
lrdchelpAuthor Commented:
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.
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
mds-cosCommented:
Back up your database (just good practice)

BEGIN TRANSACTION
UPDATE table SET lastname = 'Dr. ' + lastname

Verify results with SELECT statement to be sure update accomplished what you want

If all good:

COMMIT TRANSACTION

If not all good:
ROLLBACK TRANSACTION
0
 
Vijaya Reddy Pinnapa ReddyCommented:
UPDATE tablename
SET lastname = 'Dr. ' + lastname
0
 
Scott PletcherSenior DBACommented:
UPDATE your_tablename
SET
    Group_Dept_Name = 'Dr. ' + LastName
WHERE
    LastName IS NOT NULL AND
    LastName NOT LIKE 'Dr.%'
    --AND ...other conditions...
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now