截取字符串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

posted @ 2011-06-14 10:45  勇气  阅读(316)  评论(0编辑  收藏  举报