How to remove 1st character from a column in SQL Server

I have a table, table A, and in table A, I have field A. In field A, there are values ​​such as:

Street A Street B ,Street C Street D etc 

I would like to know if there is any SQL that will allow me to either remove the 1st character from field A, where there is.

I know where to start. I can select all rows that have a in field A, but I don’t know where to start trying to delete it.

+4
source share
4 answers
 UPDATE YourTable SET YourCol = SUBSTRING(YourCol, 2, 0+0x7fffffff) WHERE YourCol LIKE ',%' 
+3
source

If you prefer not to care about length, STUFF is the right candidate:

 UPDATE YourTable SET YourCol = STUFF(YourCol, 1, 1, '') WHERE YourCol LIKE ',%' 
+10
source

You can use RIGHT , LEN and RTRIM functions

 UPDATE TableA SET FieldA = RIGHT(RTRIM(FieldA), LEN(FieldA) - 1) WHERE FieldA LIKE ',%' 

Example

+3
source

You can use the TSQL SUBSTRING function

http://msdn.microsoft.com/en-us/library/ms187748.aspx

Use LEN to get the field length.

http://msdn.microsoft.com/en-us/library/ms190329.aspx

 SUBSTRING(FieldA, 2, LEN(FieldA) - 1) 
+2
source

Source: https://habr.com/ru/post/1487280/


All Articles