How can I select from list of values in SQL Server

后端 未结 14 1733
隐瞒了意图╮
隐瞒了意图╮ 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:51

    If you need an array, separate the array columns with a comma:

    SELECT * FROM (VALUES('WOMENS'),('MENS'),('CHILDRENS')) as X([Attribute])
    ,(VALUES(742),(318)) AS z([StoreID])
    
    0 讨论(0)
  • 2020-11-28 18:54

    Simplest way to get the distinct values of a long list of comma delimited text would be to use a find an replace with UNION to get the distinct values.

    SELECT 1
    UNION SELECT 1
    UNION SELECT 1
    UNION SELECT 2
    UNION SELECT 5
    UNION SELECT 1
    UNION SELECT 6
    

    Applied to your long line of comma delimited text

    • Find and replace every comma with UNION SELECT
    • Add a SELECT in front of the statement

    You now should have a working query

    0 讨论(0)
提交回复
热议问题