• Luis Cazares (8/27/2012)


    You were joining your grouped results with the original table with duplicates. You can get an even simpler version of your code like this, no need of a subquery:

    SELECT @MSGOUT = @MSGOUT + '

    <tr>

    <td>' + ServerName +'</td>

    <td>' + DBName +'</td>

    <td>' + cast(COUNT(dbname) as varchar(5)) +'</td>

    </tr>

    '

    FROM DBINVENTORY

    GROUP BY ServerName,DBName

    HAVING ( COUNT(DBName) > 1 )

    Thanks luis....

    Sagar Sonawane
    ** Every DBA has his day!!:cool: