Ordered Value by Column / Row

后端 未结 4 940
借酒劲吻你
借酒劲吻你 2021-01-16 15:24

Its a little difficult to explain. It might be easier to skip to the examples.

A table has an id and four columns that each allow null.

ID, Col1, Co         


        
4条回答
  •  终归单人心
    2021-01-16 15:50

    Try this one

    With MyTables as
    (
    SELECT  [Col1] as [ColX] FROM [Test].[dbo].[MyTable] 
    Union 
    SELECT  [Col2] as [ColX]   FROM [Test].[dbo].[MyTable]
    Union
    SELECT  [Col3] as [ColX]   FROM [Test].[dbo].[MyTable]
    Union
    SELECT  [Col4] as [ColX]   FROM [Test].[dbo].[MyTable]
    )
    select ColX from MyTables where ColX is not null
    

提交回复
热议问题