• MS SQL Server2k字符串分拆与合并处理代码


                           -- MS SQL Server2k字符串分拆与合并处理代码             

     --字符串分拆处理代码
    CREATE FUNCTION f_splitSTR(
    @s     varchar(8000),  --待分拆的字符串
    @split  varchar(10)     --数据分隔符
    )RETURNS TABLE
    AS
    --SELECT TOP 8000 ID=IDENTITY(int,1,1) INTO dbo.tb_splitSTR  --字符串分拆函数要用到的辅助表.
    --FROM syscolumns a,syscolumns b

    RETURN(
     SELECT col=CAST(SUBSTRING(@s,ID,CHARINDEX(@split,@s+@split,ID)-ID) as varchar(100))
     FROM tb_splitSTR
     WHERE ID<=LEN(@s+'a')
      AND CHARINDEX(@split,@split+@s,ID)=ID)
    --drop table tb_splitSTR
    GO

    /* --利用以上函数,对某一表的字符串字段字符分拆处理代码
    declare @id int,@c varchar(50)
    declare k cursor for select * from id_f --字符串待分拆原始表(id int,c varchar(50))
    open k
    fetch next from k into @id,@c
    while (@@fetch_status=0)
     begin
       insert into id_yf --分拆结果表(id int,c varchar(50))
       select @id as id,c.* from f_splitSTR(@c,',') as c
       fetch next from k into @id,@c
     end
    close k
    deallocate k
    */
    --------------------------------------------------------------------------
    --字符串合并处理代码
    declare @s varchar(300)
    set @s=''
    SELECT @s=@s+c+','
    FROM [dbo].[id_h] --字符串待合并表[id int,c varchar(50)]
    where id <> (select top 1 id from id_h order by id desc) order by id

    select @s=@s+ c from id_h where id =(select top 1 id from id_h order by id desc)
    select @s

  • 相关阅读:
    只是为了好玩——Linux之父林纳斯自传
    Unity Sprite Atlas Compression
    Bitmap动画
    UnityShader:HSV(色相,饱和度,亮度)转换
    Using Flash Builder with Flash Professional
    Flash Decompiler
    One Night Ultimate Werewolf Daybreak
    Visual Studio CLR Profiler
    Photoshop 融合属性 Unity Shader
    .NET GC
  • 原文地址:https://www.cnblogs.com/cyz1980/p/477268.html
Copyright © 2020-2023  润新知