Home Forums SQL Server 2012 SQL Server 2012 - T-SQL does following query needs union or using cases/isnull/coalace will do. RE: does following query needs union or using cases/isnull/coalace will do.

  • It might be worth trying code below, as it seems to limit the number of "j" lookups required. A nested-loop join didn't prevent the extra lookups -- for whatever reason -- so I forced a hash join.

    select a.aid, i.*, isnull(i.spoint ,j.spoint) as spoint

    from #a a

    left join #i i on a.Aid = i.aid

    left hash join #j j on (i.aid is null) and a.Aid = j.aid

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.