SQL Server removes a character in front of a string

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.