0

I have a database in which suppose i have a table named Score in Score there are two fields

  1. Id
  2. Name

now when i see that there are many names starting with - for example

-Karl-KSJ
-Jhon-Kate
-Xyz-Abc

now i want to remove leading - from all rows and update them , and leave all rows where name is not starting with - . How can i achieve that in sql . Please mind it that i have millions of records so performance will play a major role .

Thanks,

1 Answer 1

4

Try it like this, it's simple, it might be fast enough:

BEGIN TRAN

UPDATE  Score 
SET     Name = RIGHT(Name, LEN(Name) - 1)
WHERE   LEFT(Name, 1) = '-'

ROLLBACK

Here is an SQL Fiddle

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.