Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1014045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:11:43+00:00 2026-05-16T10:11:43+00:00

I am trying to develop a query to insert unique records but am receiving

  • 0

I am trying to develop a query to insert unique records but am receiving the SQL Server Primary Key error for trying to insert duplicate records. I was able to insert some values with this query but not for this record (score_14).

So now I am trying to find duplicate record with the following query. The challenge is that my PK is based on 3 columns: StudentID, MeasureDate, and MeasureID–all from a different table not mentioned below.

But this only shows me count–instead I want to just return records with count > 1. How do I do that?

select count(a.score_14) as score_count, A.studentid, A.measuredate, B.measurename+' ' +B.LabelName 
from [J5C_Measures_Sys] A
join [J5C_ListBoxMeasures_Sys] B on A.MeasureID = B.MeasureID 
join sysobjects so on so.name = 'J5C_Measures_Sys' 
join syscolumns sc on so.id = sc.id 
join [J5C_MeasureNamesV2_Sys] v on v.Score_field_id = sc.name
where so.type = 'u' and sc.name = 'score_14' and a.score_14 is not null 
AND A.STUDENTID IS NOT NULL AND A.MEASUREDATE IS NOT NULL AND B.MEASURENAME IS NOT NULL
--and count(a.score_14)>1
group by a.studentid, a.measuredate, B.measurename, B.LabelName, A.score_14
having count(a.score_14) > 1
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:11:44+00:00Added an answer on May 16, 2026 at 10:11 am

    Beth is correct – here’s my re-write of your query:

    SELECT a.studentid, a.measuredate, a.measureid
      from [J5C_Measures_Sys] A
    GROUP BY a.studentid, a.measuredate, a.measureid
      HAVING COUNT(*) > 1
    

    Previously:

    SELECT a.studentid, a.measuredate, a.measureid
      from [J5C_Measures_Sys] A
      join [J5C_ListBoxMeasures_Sys] B on A.MeasureID = B.MeasureID 
      join sysobjects so on so.name = 'J5C_Measures_Sys'
                        AND so.type = 'u'
      join syscolumns sc on so.id = sc.id 
                        and sc.name = 'score_14' 
      join [J5C_MeasureNamesV2_Sys] v on v.Score_field_id = sc.name
     where a.score_14 is not null  
       AND B.MEASURENAME IS NOT NULL
    GROUP BY a.studentid, a.measuredate, a.measureid
      HAVING COUNT(*) > 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying develop an application (C#) to query an LDAP server. I don't
I've been trying to develop a linq query that returns the ItemNumber column of
I am trying to develop a .NET Web Project using NHibernate and Spring.NET, but
I'm trying to develop a little C# application (with MS Visual Express and SQL
I am trying to develop a multimedia site and I am leaning heavily toward
I am trying to develop everything in sharepoint as features so I can easily
I am trying to develop an online translation service (sort of a personal challenge)
I'm trying to develop some SharePoint workflows for the company I work for, and
I'm trying to develop an application that will use getImageData in javascript in Firefox
I'm trying to develop a firefox extension that inserts additional HTTP header fields into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.