• 处理传递过来的拼接的值,中间用逗号相隔


    alter proc ljgl_cp_yzzx @usetag int ,@ids varchar(1000)
    as
    begin
    begin tran  tr1
    select    * into #temp  from  fn_split(@ids,',')
    
    update cp_advice set  usetag=@usetag where [objid] in (select * from #temp)
        if @@ERROR<>0  goto final    
        commit tran  tr1
        select '执行成功'  msg,1 code
        return    
        final:rollback tran  tr1
        select '执行失败'  msg,0 code
    End
    
    ---调用方法:select  *  from  fn_split('a,b',',')
    ALTER   FUNCTION    [dbo].[fn_split] ( @inputstr varchar(8000), @seprator varchar(10) ) 
    returns @temp table (a varchar(200)) 
    as 
    
    begin 
    declare @i int 
    
    set @inputstr = rtrim(ltrim(@inputstr)) 
    set @i = charindex(@seprator, @inputstr) 
    
    while @i >= 1 
    begin 
    insert @temp values(left(@inputstr, @i - 1)) 
    
    set @inputstr = substring(@inputstr, @i +1, len(@inputstr) - @i) 
    set @i = charindex(@seprator, @inputstr) 
    end 
    
    if @inputstr <> '' 
    insert @temp values(@inputstr) 
    
    return 
    end 
    
    
    select  @code,@Name,@Phone,@Visit_people,DATEADD(D,ts,GETDATE()) ,lx,zt,0 from hfjhzq where zqid in (select * from [dbo].[fn_split](@Visit_ids,','))
    
     FUNCTION    [dbo].[fn_split] ( @inputstr varchar(8000), @seprator varchar(10) ) 
    returns @temp table (a varchar(200)) 
    as 
    
    begin 
    declare @i int 
    
    set @inputstr = rtrim(ltrim(@inputstr)) 
    set @i = charindex(@seprator, @inputstr) 
    
    while @i >= 1 
    begin 
    insert @temp values(left(@inputstr, @i - 1)) 
    
    set @inputstr = substring(@inputstr, @i +1, len(@inputstr) - @i) 
    set @i = charindex(@seprator, @inputstr) 
    end 
    
    if @inputstr <> '' 
    insert @temp values(@inputstr) 
    
    return 
    end 
  • 相关阅读:
    HashCode和equal方法的区别和联系 [转]
    Linux makefile 教程 [转]
    gcc: multiple definition of [转]
    conda虚拟环默认路径
    terrasolid修改背景颜色
    台式机无法开机可能的原因
    TensorFlow2.1中计算平方函数的tf.square()的用法
    Terrasolid 安装教程
    如何解决Pytorch的GPU driver is too old的问题?
    使用 TensorBoard 可视化进行监督
  • 原文地址:https://www.cnblogs.com/xiaozizi/p/5816851.html
Copyright © 2020-2023  润新知