String.Join in SQL

前端 未结 4 609
独厮守ぢ
独厮守ぢ 2021-01-18 19:17

i want to select from a Table called RMA(simplified):

 idRMA| RMA_Number
 -----------------------
 1      RMA0006701
 2      RMA0006730
 3               


        
4条回答
  •  太阳男子
    2021-01-18 20:09

    Here is something that should get you going:

    ALTER FUNCTION [dbo].[GetUCColumns]
    (@tableid INT, @index INT)
    RETURNS VARCHAR (MAX)
    AS
    BEGIN
    
        DECLARE @cols varchar(max)
    
        SELECT @cols = COALESCE(@cols + ', ', '') + [name]
        FROM [sys].[columns]
        where object_id = @tableid AND column_id IN 
        (SELECT [column_id]
          FROM [sys].[index_columns]
          where object_id = @tableid AND @index = index_id)
    
        RETURN @cols
        END
    

提交回复
热议问题