Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics GP (Archived)

Management Reporter receiving Violation of Primary Key constraint PK_PeriodsByDate.

(0) ShareShare
ReportReport
Posted on by 650

Receiving the following error in MR 2012 Configuration Console. Violation of PRIMARY KEY constraint 'PK_PeriodsByDate'. Cannot insert duplicate key in object 'dbo.PeriodsByDate'. The duplicate key value is (2, 2007-01-01).

*This post is locked for comments

  • Suggested answer
    kmalone43 Profile Picture
    894 on at
    RE: Management Reporter receiving Violation of Primary Key constraint PK_PeriodsByDate.

    Found a solution.  The key referenced in the datamart.PeriodsByDate is the OrganizationID (sequence of company added to MR DataMart & not the same as CompanyId in GP) & the starting date of fiscal period.

    You can see which GP company the organizationID pertains to from

    Select * from Datamart.Organization

    Now that we have the company identified, there are 2 issues that can likely lead to this error, both are within the SY40100 table.  There can be 2 fiscal periods with the same starting fiscal date OR there can be fiscal periods with incorrect ending dates (only seen in SQL and not within GP).

    To check duplicate starting fiscal dates.

    Select '{Co}' as Company, PERIODID, YEAR1 from {Co}.dbo.SY40100
      where FORIGIN in (0,1) and ODESCTN in ('', 'General Entry')
      group by YEAR1, PERIODID
      having COUNT(PERIODID)<>2
       order by Company, YEAR1,PERIODID

    To check for incorrect ending dates.

     Select Perioddt as PDT, Perdendt as PEDT, DATEDIFF(day,Perioddt,Perdendt) as 'Days', year1, periodid, *

    from {Co}.dbo.SY40100 where --YEAR1=2008 and
       series=0 and pername <> 'Beginning Balance'
       and DATEDIFF(day,Perioddt,Perdendt) > 31
        order by  perioddt

    For either one, the solution to fix is to re-calculate the fiscal years from within GP & then run the Reconcile utility under Financial>>Utilities>>Reconcile.

    From here, if the DataMart is still trying to sync the company & you're still receiving the original error, you can delete the incorrect periods from staging table that leads to the DataMart.periodsbydate table.

    Here's the script to clear the instance where the original fiscal ending dates were incorrect.

    select datediff(day,starts,ends) as 'days',* from datamart.periodstaging
    where datediff(day,starts,ends) > 31

    delete from datamart.periodstaging where datediff(day,starts,ends) > 31

    Hope this helps!

  • kmalone43 Profile Picture
    894 on at
    RE: Management Reporter receiving Violation of Primary Key constraint PK_PeriodsByDate.

    Hi Deb, I'm inexplicably seeing this error when rebuilding the DataMart.  Did you ever find a cause/solution to your case?

    Thanks,

    Kyle

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >

Featured topics

Product updates

Dynamics 365 release plans