Home Forums SQL Server 2005 T-SQL (SS2K5) Working with coalesce on a view RE: Working with coalesce on a view<!-- 864 -->

  • Your problem is the double FULL OUTER JOIN as you can see if you use SELECT * to show all rows and columns.

    Here's an alternative, but you should reevaluate the need of the full joins.

    SELECT COALESCE(TPHY.HCPCS, TOUT.HCPCS, TDME.HCPCS) AS HCPCS

    , COALESCE(MAX(UNITS_PHY), -1) AS UNITS_PHY

    , COALESCE(MAX(UNITS_OUT), -1) AS UNITS_OUT

    , COALESCE(MAX(UNITS_DME), -1) AS UNITS_DME

    FROM MUES_PHY_2010_07 TPHY

    FULL JOIN MUES_OUT_2010_07 TOUT ON TPHY.HCPCS = TOUT.HCPCS

    FULL JOIN MUES_DME_2010_07 TDME ON TPHY.HCPCS = TDME.HCPCS

    GROUP BY COALESCE(TPHY.HCPCS, TOUT.HCPCS, TDME.HCPCS)

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2