If it is a primary key, you can be certain that in the actual table you do not have duplicate rows with the same storeactivityid
.
Your query returns rows with the same storeactivityid
because at least one of the joined tables has the matches the condition specified in the join.
My best guess it is due to the followoing join:
inner join payperiods pp with (nolock) on pd.enddatetime between pp.begindate and pp.enddate and pp.CompanyID = @companyid
Is it possible that a company has multiple payrolldetails
within the same range of dates specified in the payperiods
table?