Because this side of the database is more, the data is more, but there is a legacy of historical data problems; A string preceded by a comma;
Now the demand is to get rid of the English comma, with a script to run the database is also OK, but here with SQL statements to remove;
Here's the complete code, here's a record.
DECLARE @cursor CURSOR;DECLARE @id int;DECLARE @Staging varchar(Max);DECLARE @Staging_tmp varchar(Max);DECLARE @str_len int;DECLARE @start_num int;Set @cursor = CURSOR for SELECTId,staging fromProj_dong_infowhereStaging<> "' andStaging is not NULL;OPEN @cursor FETCH NEXT from @cursor into @id,@Staging while(@ @FETCH_STATUS=0) BEGIN SET @Staging_tmp = LTrim(@Staging); SET @start_num = Patindex('%,%',@Staging_tmp); IF @start_num = 1 BEGIN SET @start_num = Patindex('%,%',@Staging); SET @str_len = datalength(@Staging); SET @Staging = substring(@Staging,@start_num+1,@str_len); --PRINT @Staging; --PRINT @id; UpdateProj_dong_infoSetStaging= @Staging whereId= @id; END FETCH NEXT from @cursor into @id,@Staging END CLOSE @cursor deallocate @cursor
SQL Server removes a character in front of a string