web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

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

I have the same question (0)
  • kmalone43 Profile Picture
    894 on at

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

    Thanks,

    Kyle

  • Suggested answer
    kmalone43 Profile Picture
    894 on at

    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!

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics GP (Archived)

#1
mtabor Profile Picture

mtabor 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans