Sql COALESCE entire rows?

前端 未结 4 1963
南笙
南笙 2021-01-18 08:21

I just learned about COALESCE and I\'m wondering if it\'s possible to COALESCE an entire row of data between two tables? If not, what\'s the best approach to the following r

4条回答
  •  佛祖请我去吃肉
    2021-01-18 08:53

    I don't think the COALESCE function can be used for what you're thinking. COALESCE is similar to ISNULL, except it allows you to pass in multiple columns, and will return the first non-null value:

    SELECT Name, Class, Color, ProductNumber,
    COALESCE(Class, Color, ProductNumber) AS FirstNotNull
    FROM Production.Product
    

    This article should explain it's application:

    http://msdn.microsoft.com/en-us/library/ms190349.aspx

    It sounds like Larry Lustig's answer is more along the lines of what you need though.

提交回复
热议问题