Why do you need the duplicate count in a variable? What will you do with the variable after it is assigned? Also, how do you define duplicates in your case? For a simple example:declare @t table (a int, b int, c int)insert into @t values (1,2,3), (1,2,3)select a, b, count(*) as duplicates from @tgroup by a, bhaving count(*) > 1
produces:a b duplicates1 2 2
and with the same table variableif exists ( select a, b from @t group by a, b having count(*) > 1 ) print 'duplicates exist'
produces:(1 row(s) affected)duplicates exist