Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a Table, Table A, and in table A I have Field A. There are values in field A like the following:

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 a ,.

I have know idea where to start I can select all the rows which have a , in Field A but I don't know where to start when trying to remove it.

like image 238
w3n2u Avatar asked Jun 20 '13 11:06

w3n2u


2 Answers

If you'd rather not care about the length, STUFF is the right candidate :

UPDATE YourTable
SET    YourCol = STUFF(YourCol, 1, 1, '')
WHERE YourCol LIKE ',%'
like image 57
Serge Avatar answered Oct 26 '22 19:10

Serge


UPDATE YourTable
SET    YourCol = SUBSTRING(YourCol, 2, 0+0x7fffffff) 
WHERE YourCol LIKE ',%'
like image 30
Martin Smith Avatar answered Oct 26 '22 17:10

Martin Smith