Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have huge list of records stored in the SQL Server 2012 which consist of some record starting with 12). and some starting with (12. I want to remove number and want to make it starting directly Like "hi this is XYZ".

How can i ??

What I have tried:

Currently i am making it manually by making changes in the database.
Posted
Updated 13-Feb-17 1:17am
v2

UPDATE A
SET A.Name =
CASE
WHEN LEFT(B.Name, 3) = '12.' THEN RTRIM(LTRIM(REPLACE(B.NAME, LEFT(B.Name, 3), '')))
WHEN LEFT(B.Name, 2) = '12' THEN RTRIM(LTRIM(REPLACE(B.NAME, LEFT(B.Name, 2), '')))

ELSE B.Name
END

FROM TableName A
INNER JOIN TableName B
ON A.PK_ID = B.PK_ID
 
Share this answer
 
You can use REPLACE() to clean it up.

If you only want to display it differently you can do something like:
SQL
SELECT REPLACE(REPLACE(field1, '12).', ''), '(12.', '') -- replace strings with blanks
FROM table1 
ORDER BY  REPLACE(REPLACE(field1, '12).', ''), '(12.', '') 


You can update it the same way
SQL
UPDATE table1 SET field1 = REPLACE(REPLACE(field1, '12).', ''), '(12.', '') -- replace strings with blanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900