zoukankan      html  css  js  c++  java
  • sql2008 将行转为字符串, 将字符串转为行 互转

    --将行转为字符串
    select stuff((select top 20 ','+ QQ from dl_QQ where uiid=1 order by tim desc for xml path('')),1,1,'')
    
    
    
    
    -- =============================================
     
    -- Description:	将字符串转为表格
    /*
    	例:select * from [f_split]('spu0987*5//spu0988*5/spu0989*5', '/')
    	--将表格转为字符串
    	DECLARE @S nVARCHAR(max)
    SELECT @S=ISNULL(@S+',','')+[col] FROM [f_split]('spu0987*5//spu0988*5/spu0989*5', '/')
    PRINT @S
    */
    -- =============================================
    create function [dbo].[strToTab](@c varchar(max),@split varchar(2))  
    returns @t table(col nvarchar(255))  
    as  
        begin  
       
          while(charindex(@split,@c)<>0)  
            begin  
              insert   @t(col)   values   (substring(@c,1,charindex(@split,@c)-1))  
              set   @c   =   stuff(@c,1,charindex(@split,@c),'')  
            end  
          insert   @t(col)   values   (@c)  
          return  
        end
    

      

  • 相关阅读:
    CSS 基础(一)
    74.Search a 2D Matrix
    73.Set Matrix Zeroes
    66.Plus One
    64.Minimum Path Sum
    63.Unique Paths II
    62.Unique Paths
    54.Spiral Matrix
    59.Spiral Matrix II
    55.Jump Game
  • 原文地址:https://www.cnblogs.com/chengulv/p/4133528.html
Copyright © 2011-2022 走看看