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

Community site session details

Session Id :
Microsoft Dynamics RMS (Archived)

DUPLICATE SUPPLIERS

(0) ShareShare
ReportReport
Posted on by 1,444

We running RMS store  version 2.0.2007 and HQ version 2.0.2007.We have 5+ stores,recently suppliers started to duplicate themselves in one of the stores.I assumed maybe a worksheet from HQ might have caused that,but to my surprise there was no worksheet associated to this.After manually deleting the duplicate suppliers this has started happening to all the branches but happens at different intervals.The most interesting thing is that supplier code and supplier name for the duplicated supplier are the same and the right supplier code is under account number.How do i stop this duplication of suppliers?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    archelle16 Profile Picture
    1,743 on at
    RE: DUPLICATE SUPPLIERS

    To remove duplicate supplier on ALL STORES

    We need to issue 2 worksheet sql to all affected stores.

    1. Create the stored procedure under all store.

            * Issue Worksheet sql, select all stores.

            * Under contents, add two rows.

            * Copy and paste this query in 1st row (Priority 1)

    IF EXISTS ( SELECT * FROM dbo.sysobjects WHERE id =       OBJECT_ID('fixMultipleSupplier') ) BEGIN DROP PROCEDURE fixMultipleSupplier END

            * Next, copy and paste this query on 2nd row (priority 2)

    CREATE PROCEDURE [dbo].[fixMultipleSupplier] @run AS BIT

    AS

       BEGIN

           IF ( @run = 1 )

               BEGIN

                   IF EXISTS ( SELECT  hqid ,

                                       supplierName ,

                                       COUNT(*) AS myCount

                               FROM    Supplier

                               GROUP BY hqid ,

                                       supplierName

                               HAVING  COUNT(*) > 1 )

                       BEGIN

                           IF OBJECT_ID('tempdb..#RetainSupplier') IS NOT NULL

                               DROP TABLE #RetainSupplier

                           SELECT  tr.hqid ,

                                   MIN(S.id) AS minID

                           INTO    #RetainSupplier

                           FROM    ( SELECT    hqid ,

                                               supplierName ,

                                               COUNT(*) AS myCount

                                     FROM      Supplier

                                     GROUP BY  hqid ,

                                               supplierName

                                     HAVING    COUNT(*) > 1

                                   ) AS tr

                                   INNER JOIN dbo.Supplier s ON s.HQID = tr.hqid

                           GROUP BY tr.hqid

                           UPDATE  Item

                           SET     SupplierID = r.minID

                           FROM    dbo.Item i

                                   INNER JOIN dbo.Supplier s ON s.ID = i.SupplierID

                                   INNER JOIN #RetainSupplier r ON r.hqid = s.HQID

                           WHERE   i.SupplierID != r.minID

                           UPDATE  dbo.SupplierList

                           SET     SupplierID = r.minID

                           FROM    SupplierList sl

                                   INNER JOIN dbo.Supplier s ON s.ID = sl.SupplierID

                                   INNER JOIN #RetainSupplier r ON r.hqid = s.HQID

                           WHERE   sl.SupplierID != r.minID

                           UPDATE  dbo.PurchaseOrder

                           SET     SupplierID = R.minID

                           FROM    PurchaseOrder po

                                   INNER JOIN dbo.Supplier s ON s.ID = po.SupplierID

                                   INNER JOIN #RetainSupplier r ON r.hqid = s.HQID

                           WHERE   po.SupplierID != r.minID

                           UPDATE  dbo.ItemClass

                           SET     SupplierID = r.minID

                           FROM    dbo.ItemClass ic

                                   INNER JOIN dbo.Supplier s ON s.ID = ic.SupplierID

                                   INNER JOIN #RetainSupplier r ON r.hqid = s.HQID

                           WHERE   ic.SupplierID != r.minID

                           DELETE  FROM dbo.Supplier

                           FROM    dbo.Supplier s

                                   INNER JOIN #RetainSupplier r ON r.HQID = s.HQID

                           WHERE   s.ID != R.minID

                       END

               END

           ELSE

               BEGIN

                   SELECT  HQID ,

                           supplierName ,

                           Code ,

                           COUNT(*) AS RecordCount

                   FROM    Supplier

                   GROUP BY hqid ,

                           supplierName ,

                           Code

                   HAVING  COUNT(*) > 1

               END

       END

              * Approve the worksheet.

    2. Execute the stored procedure to fix duplicates.

      * Issue worksheet sql to all stores.

      * Under contents, copy and paste the query to 1st row (priority 1)

    EXEC [fixMultipleSupplier] @Run=1

    SYNC ALL AFFECTED STORES!

  • Suggested answer
    archelle16 Profile Picture
    1,743 on at
    RE: DUPLICATE SUPPLIERS

    To remove duplicate supplier on single store, execute to build the stored procedure

    /****** Object:  StoredProcedure [dbo].[fixMultipleSupplier]    Script Date: 08/06/2015 12:31:48 ******/

    SET ANSI_NULLS ON

    GO

    SET QUOTED_IDENTIFIER ON

    GO

    CREATE PROCEDURE [dbo].[fixMultipleSupplier] @run AS BIT

    AS

       BEGIN

           IF ( @run = 1 )

               BEGIN

                   IF EXISTS ( SELECT  hqid ,

                                       supplierName ,

                                       COUNT(*) AS myCount

                               FROM    Supplier

                               GROUP BY hqid ,

                                       supplierName

                               HAVING  COUNT(*) > 1 )

                       BEGIN

                           IF OBJECT_ID('tempdb..#RetainSupplier') IS NOT NULL

                               DROP TABLE #RetainSupplier

                           SELECT  tr.hqid ,

                                   MIN(S.id) AS minID

                           INTO    #RetainSupplier

                           FROM    ( SELECT    hqid ,

                                               supplierName ,

                                               COUNT(*) AS myCount

                                     FROM      Supplier

                                     GROUP BY  hqid ,

                                               supplierName

                                     HAVING    COUNT(*) > 1

                                   ) AS tr

                                   INNER JOIN dbo.Supplier s ON s.HQID = tr.hqid

                           GROUP BY tr.hqid

                           UPDATE  Item

                           SET     SupplierID = r.minID

                           FROM    dbo.Item i

                                   INNER JOIN dbo.Supplier s ON s.ID = i.SupplierID

                                   INNER JOIN #RetainSupplier r ON r.hqid = s.HQID

                           WHERE   i.SupplierID != r.minID

                           UPDATE  dbo.SupplierList

                           SET     SupplierID = r.minID

                           FROM    SupplierList sl

                                   INNER JOIN dbo.Supplier s ON s.ID = sl.SupplierID

                                   INNER JOIN #RetainSupplier r ON r.hqid = s.HQID

                           WHERE   sl.SupplierID != r.minID

                           UPDATE  dbo.PurchaseOrder

                           SET     SupplierID = R.minID

                           FROM    PurchaseOrder po

                                   INNER JOIN dbo.Supplier s ON s.ID = po.SupplierID

                                   INNER JOIN #RetainSupplier r ON r.hqid = s.HQID

                           WHERE   po.SupplierID != r.minID

                           UPDATE  dbo.ItemClass

                           SET     SupplierID = r.minID

                           FROM    dbo.ItemClass ic

                                   INNER JOIN dbo.Supplier s ON s.ID = ic.SupplierID

                                   INNER JOIN #RetainSupplier r ON r.hqid = s.HQID

                           WHERE   ic.SupplierID != r.minID

                           DELETE  FROM dbo.Supplier

                           FROM    dbo.Supplier s

                                   INNER JOIN #RetainSupplier r ON r.HQID = s.HQID

                           WHERE   s.ID != R.minID

                       END

               END

           ELSE

               BEGIN

                   SELECT  HQID ,

                           supplierName ,

                           Code ,

                           COUNT(*) AS RecordCount

                   FROM    Supplier

                   GROUP BY hqid ,

                           supplierName ,

                           Code

                   HAVING  COUNT(*) > 1

               END

       END

    GO

    To view the number of duplicate suppliers

    run this syntax,

    EXEC [fixMultipleSupplier] @Run=0

    To fix,

    EXEC [fixMultipleSupplier] @Run=1

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics RMS (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans