How can I select from list of values in SQL Server

后端 未结 14 1846
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 18:08

I have very simple problem that I can\'t solve. I need to do something like this:

select distinct * from (1, 1, 1, 2, 5, 1, 6).

Anybody can

14条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 18:30

    Another way that you can use is a query like this:

    SELECT DISTINCT
        LTRIM(m.n.value('.[1]','varchar(8000)')) as columnName
    FROM 
        (SELECT CAST('' + REPLACE(t.val,',','') + '' AS XML) AS x
         FROM (SELECT '1, 1, 1, 2, 5, 1, 6') AS t(val)
        ) dt
      CROSS APPLY 
        x.nodes('/XMLRoot/RowData') m(n);
    

提交回复
热议问题