SQL Server – How to Remove a Period If It Is the First Character in a Varchar Column

functionssql servert-sql

I am migrating data from an old system into a new system I am building and have found someone is doing a bad practice of adding a period to the start of some people's names to make them appear first in some drop down lists. I am trying to figure out how I can remove these periods when they are the first character of the column with out removing periods later in the name (like for Middle Initials). This change is being made during and INSERT INTO SELECT command.

Best Answer

One option is using a CASE statement, such as this one:

CASE WHEN LEFT(MyColumn,1)='.' THEN RIGHT(MyColumn, LEN(MyColumn)-1) ELSE MyColumn END