截取字符串1,2,3,4,5

declare @split varchar(2)
set @split=','

while(CHARINDEX(@split,@SalesDate)<>0)
   begin
    insert into SP_SpecialsCommodityEveryday
    (
     S_Id,C_Id,SalesWeek,LimitAmount
    )
    values
    (
     @return_Id,@C_Id,substring(@SalesDate,1,charindex(@split,@SalesDate)-1),@LimitAmount
    )
    
    IF( @@ERROR <> 0 )
    BEGIN
     GOTO Cleanup
    END
    set @SalesDate=stuff(@SalesDate,1,CHARINDEX(@split,@SalesDate),'')
   end

if @SalesDate<>''
   begin
    insert into SP_SpecialsCommodityEveryday
    (
     S_Id,C_Id,SalesWeek,LimitAmount
    )
    values
    (
     @return_Id,@C_Id,@SalesDate,@LimitAmount
    )
    
    IF( @@ERROR <> 0 )
    BEGIN
     GOTO Cleanup
    END
   end

你可能感兴趣的:(截取字符串)