Compare tables with count

  • Hi Team,

    using below script to compare two tables and get the values.

    how to get the count of 'Table A' , 'Table B' , 'Table A & Table B' using below script.

    Ex:

    'Table A' -- 150

    'Table B' -- 300

    'Table A & Table B' -- 150

    SELECT

    Col1 = ISNULL(a.name,b.name),

    Col2 =

    CASE

    WHEN ISNULL(a.name,'') = '' THEN 'Table B'

    WHEN ISNULL(b.name,'') = '' THEN 'Table A'

    ELSE 'Table A & Table B'

    END

    FROM #tableA a

    FULL JOIN #tableB b

    ON a.name = b.name;

  • Take a look at this thread:

    http://www.sqlservercentral.com/Forums/Topic1678555-3077-2.aspx#bm1679472

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply