Home Forums SQL Server 2008 T-SQL (SS2K8) Some way to write an INNER JOIN, but joining on either of two columns RE: Some way to write an INNER JOIN, but joining on either of two columns

  • What is the problem? Do you have NULLs in the the MainZip when it's not present/used?

    SELECT D.*

    FROM Doctors D

    INNER JOIN ZipCodes Z ON

    (D.MainZip IS NOT NULL AND D.MainZip = Z.ZipCode) OR

    (D.MainZip IS NULL AND D.AlternateZip = Z.ZipCode)

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