去重,以逗号分开字符串

SELECT a.Dep  from
(SELECT 
--列名
--ROW_NUMBER() over(order by (select 1)) as id,
            c.value('.', 'varchar(50)') AS Dep 
   FROM     uf_ncr_jtbmqy a
            CROSS APPLY ( SELECT    CAST('<row>' + REPLACE(CAST(Dep AS NVARCHAR(4000)) , ',',
                                                           '</row><row>')
                                    + '</row>' AS XML) AS xmlcode
                        ) C1
            CROSS APPLY xmlcode.nodes('*') t ( c )
            ) a
        GROUP BY Dep 

 

posted @ 2023-04-12 15:57  血月葬花魂  阅读(20)  评论(0编辑  收藏  举报