zoukankan      html  css  js  c++  java
  • sql split使用

    Code
    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    go

    ALTER FUNCTION [dbo].[f_Split](@temp varchar(8000),@parting char(1)) 
    --f_Split 
    --
    @temp为参数名 varchar为参数类型 8000为类型长度 @parting为参数名 char类型
    --分割
    SQL字符串 
    RETURNS varchar(8000
    --返回类型为varchar长度为4000 
    AS 
    BEGIN 
        
    Declare @i int,@str char(15),@formattemp char(12),@s varchar(8000)
          
    --SET @temp='0000022016,0000022022,0000022017,0000022021'      
          set @s=''

          
    SET @temp=Rtrim(Ltrim(@temp))
          
    SET @i=charIndex(@parting,@temp)--从temp起始位置开始搜索"."的起始位置
          --create table #t (ip char(15))--创建临时表
               While @i>=1

                    
    BEGIN
                        
    set @str=left(@temp,@i-1)
                        
    --insert into #t values(@str)
                        
                        
    set @s=@s+''''+rtrim(ltrim(@str))+''''+','
                        
    SET @temp=substring(@temp,@i+1,len(@temp)-@i)
                        
    SET @i=charIndex(@parting,@temp)
                    
    END
        
    --set @s=@s+''''+rtrim(ltrim(@str))+''''+','
        set @s=@s+''''+@temp+''''
        
    return Substring(@s,1,len(@s))
    END 

    print dbo.f_split('0000022016,0000022022,0000022017,0000022021',',')
  • 相关阅读:
    Easyui使用记录
    Ubuntu 设置UFW防火墙
    MySQL 官方文档
    MySQL 版本
    MySQL主从架构之Master-Master互为主备
    MySQL主从架构之Master-Slave-Slave级联
    MySQL主从架构之Master-Slave主从同步
    Linux crond实例
    Ubuntu su: Authentication failure
    MySQL基准测试
  • 原文地址:https://www.cnblogs.com/jinweida/p/1444562.html
Copyright © 2011-2022 走看看