sql 使用split 分隔自符串,进行循环

时间:2022-02-02 21:46:23
ALTER procedure [dbo].[proName]
 @Ids varchar(1000),
 @submitDate date 
 as
 begin
    declare @i int
    set @Ids=rtrim(ltrim(@Ids))
    set @i=CHARINDEX(';',@Ids)
    while @i>=1
    begin
        insert into tbName(guidName1,guidName2,SubmitDate)
        values(NEWID(),convert(uniqueidentifier,left(@Ids,@i-1)),convert(datetime,@submitDate))

        set @Ids=substring(@Ids,@i+1,len(@Ids)-@i)
        set @i=CHARINDEX(';',@Ids)
    end
 end