Home Forums SQL Server 2005 T-SQL (SS2K5) compare column names from two tables in same database RE: compare column names from two tables in same database

  • You want to change the INNER join to a FULL OUTER join and then use the WHERE to give you records that do not have a match.

    [font="Courier New"]SELECT

    *

    FROM

    Information_Schema.Columns A

    FULL OUTER JOIN Information_Schema.Columns B ON A.Column_Name = B.Column_Name

    AND B.Table_Name = 'FY2007_DATA'

    AND B.Table_Schema = 'dbo'

    WHERE

    A.Table_Schema = 'dbo'

    AND A.Table_Name = 'FY2006_DATA'

    AND (A.Column_Name IS NULL OR B.Column_Name IS NULL)[/font]