How to find and remove duplicates in SQL Server












1














Described about my issue in IMAGE



I am using below joins to get certain data. I am getting 6 rows instead of 3. Can anyone help me out?



ALTER PROCEDURE [dbo].[psGetClientDropdownResult]   
@lblCustomer VARCHAR(40),
@lblDeliveryplace VARCHAR(41),
@lblPackedProduct VARCHAR(41)
AS
BEGIN
SET NOCOUNT ON;

SELECT DISTINCT
Customer.lblCustomer As ClientDestinataire,
DeliveryPlace.lblDeliveryplace As LieuDeLivraison,
DeliveryPlace.codCountry AS Pays,
CustomerProduct.codCustomerProduct As CodeProduitClient,
CustomerProduct.codCustomerProductColor AS CodeCouleurClient,
CustomerProduct.codAqp AS AQP,
DeliveryPlace.codEMSupplier AS CodeFournisseurEMPourClient,
CustomerProduct.datApplication AS DateDApplication,
CustomerProduct.codPackedProduct AS Material,
Product.lblPProduct AS Produit,
Product.lblProduct AS RefFournisseur,
PackedProduct.lblPackedProduct AS MaterialDescription,
Packaging.nbrPackagingNetWeight AS PoidsNet,
(Packaging.nbrPackagingNetWeight) + (Packaging.nbrAddWeightFromNetToGross) AS PoidsBrut,
Customer.codCustomer as CodClient,
PackedProduct.codPackedProduct as Material,
Packaging.codPackaging as CodPackaging,
Packaging.nbrWeightCoefFromNetToGross as CoefNetBrut
FROM
Customer
INNER JOIN
CustomerProduct ON Customer.codCustomer = CustomerProduct.codCustomer
INNER JOIN
DeliveryPlace ON Customer.codCustomer = DeliveryPlace.codCustomer
INNER JOIN
PackedProduct ON CustomerProduct.codPackedProduct = PackedProduct.codPackedProduct
INNER JOIN
Product ON PackedProduct.codProduct = Product.codProduct
INNER JOIN
Packaging on Packaging.codPackaging = PackedProduct.codPackaging
WHERE
(Customer.lblCustomer = @lblCustomer or @lblCustomer IS NULL )
AND (DeliveryPlace.lblDeliveryplace = @lblDeliveryplace OR @lblDeliveryplace IS NULL)
AND (PackedProduct.lblPackedProduct = @lblPackedProduct OR @lblPackedProduct IS NULL)


I need help to understand how can i stop getting my records duplicates.










share|improve this question





























    1














    Described about my issue in IMAGE



    I am using below joins to get certain data. I am getting 6 rows instead of 3. Can anyone help me out?



    ALTER PROCEDURE [dbo].[psGetClientDropdownResult]   
    @lblCustomer VARCHAR(40),
    @lblDeliveryplace VARCHAR(41),
    @lblPackedProduct VARCHAR(41)
    AS
    BEGIN
    SET NOCOUNT ON;

    SELECT DISTINCT
    Customer.lblCustomer As ClientDestinataire,
    DeliveryPlace.lblDeliveryplace As LieuDeLivraison,
    DeliveryPlace.codCountry AS Pays,
    CustomerProduct.codCustomerProduct As CodeProduitClient,
    CustomerProduct.codCustomerProductColor AS CodeCouleurClient,
    CustomerProduct.codAqp AS AQP,
    DeliveryPlace.codEMSupplier AS CodeFournisseurEMPourClient,
    CustomerProduct.datApplication AS DateDApplication,
    CustomerProduct.codPackedProduct AS Material,
    Product.lblPProduct AS Produit,
    Product.lblProduct AS RefFournisseur,
    PackedProduct.lblPackedProduct AS MaterialDescription,
    Packaging.nbrPackagingNetWeight AS PoidsNet,
    (Packaging.nbrPackagingNetWeight) + (Packaging.nbrAddWeightFromNetToGross) AS PoidsBrut,
    Customer.codCustomer as CodClient,
    PackedProduct.codPackedProduct as Material,
    Packaging.codPackaging as CodPackaging,
    Packaging.nbrWeightCoefFromNetToGross as CoefNetBrut
    FROM
    Customer
    INNER JOIN
    CustomerProduct ON Customer.codCustomer = CustomerProduct.codCustomer
    INNER JOIN
    DeliveryPlace ON Customer.codCustomer = DeliveryPlace.codCustomer
    INNER JOIN
    PackedProduct ON CustomerProduct.codPackedProduct = PackedProduct.codPackedProduct
    INNER JOIN
    Product ON PackedProduct.codProduct = Product.codProduct
    INNER JOIN
    Packaging on Packaging.codPackaging = PackedProduct.codPackaging
    WHERE
    (Customer.lblCustomer = @lblCustomer or @lblCustomer IS NULL )
    AND (DeliveryPlace.lblDeliveryplace = @lblDeliveryplace OR @lblDeliveryplace IS NULL)
    AND (PackedProduct.lblPackedProduct = @lblPackedProduct OR @lblPackedProduct IS NULL)


    I need help to understand how can i stop getting my records duplicates.










    share|improve this question



























      1












      1








      1







      Described about my issue in IMAGE



      I am using below joins to get certain data. I am getting 6 rows instead of 3. Can anyone help me out?



      ALTER PROCEDURE [dbo].[psGetClientDropdownResult]   
      @lblCustomer VARCHAR(40),
      @lblDeliveryplace VARCHAR(41),
      @lblPackedProduct VARCHAR(41)
      AS
      BEGIN
      SET NOCOUNT ON;

      SELECT DISTINCT
      Customer.lblCustomer As ClientDestinataire,
      DeliveryPlace.lblDeliveryplace As LieuDeLivraison,
      DeliveryPlace.codCountry AS Pays,
      CustomerProduct.codCustomerProduct As CodeProduitClient,
      CustomerProduct.codCustomerProductColor AS CodeCouleurClient,
      CustomerProduct.codAqp AS AQP,
      DeliveryPlace.codEMSupplier AS CodeFournisseurEMPourClient,
      CustomerProduct.datApplication AS DateDApplication,
      CustomerProduct.codPackedProduct AS Material,
      Product.lblPProduct AS Produit,
      Product.lblProduct AS RefFournisseur,
      PackedProduct.lblPackedProduct AS MaterialDescription,
      Packaging.nbrPackagingNetWeight AS PoidsNet,
      (Packaging.nbrPackagingNetWeight) + (Packaging.nbrAddWeightFromNetToGross) AS PoidsBrut,
      Customer.codCustomer as CodClient,
      PackedProduct.codPackedProduct as Material,
      Packaging.codPackaging as CodPackaging,
      Packaging.nbrWeightCoefFromNetToGross as CoefNetBrut
      FROM
      Customer
      INNER JOIN
      CustomerProduct ON Customer.codCustomer = CustomerProduct.codCustomer
      INNER JOIN
      DeliveryPlace ON Customer.codCustomer = DeliveryPlace.codCustomer
      INNER JOIN
      PackedProduct ON CustomerProduct.codPackedProduct = PackedProduct.codPackedProduct
      INNER JOIN
      Product ON PackedProduct.codProduct = Product.codProduct
      INNER JOIN
      Packaging on Packaging.codPackaging = PackedProduct.codPackaging
      WHERE
      (Customer.lblCustomer = @lblCustomer or @lblCustomer IS NULL )
      AND (DeliveryPlace.lblDeliveryplace = @lblDeliveryplace OR @lblDeliveryplace IS NULL)
      AND (PackedProduct.lblPackedProduct = @lblPackedProduct OR @lblPackedProduct IS NULL)


      I need help to understand how can i stop getting my records duplicates.










      share|improve this question















      Described about my issue in IMAGE



      I am using below joins to get certain data. I am getting 6 rows instead of 3. Can anyone help me out?



      ALTER PROCEDURE [dbo].[psGetClientDropdownResult]   
      @lblCustomer VARCHAR(40),
      @lblDeliveryplace VARCHAR(41),
      @lblPackedProduct VARCHAR(41)
      AS
      BEGIN
      SET NOCOUNT ON;

      SELECT DISTINCT
      Customer.lblCustomer As ClientDestinataire,
      DeliveryPlace.lblDeliveryplace As LieuDeLivraison,
      DeliveryPlace.codCountry AS Pays,
      CustomerProduct.codCustomerProduct As CodeProduitClient,
      CustomerProduct.codCustomerProductColor AS CodeCouleurClient,
      CustomerProduct.codAqp AS AQP,
      DeliveryPlace.codEMSupplier AS CodeFournisseurEMPourClient,
      CustomerProduct.datApplication AS DateDApplication,
      CustomerProduct.codPackedProduct AS Material,
      Product.lblPProduct AS Produit,
      Product.lblProduct AS RefFournisseur,
      PackedProduct.lblPackedProduct AS MaterialDescription,
      Packaging.nbrPackagingNetWeight AS PoidsNet,
      (Packaging.nbrPackagingNetWeight) + (Packaging.nbrAddWeightFromNetToGross) AS PoidsBrut,
      Customer.codCustomer as CodClient,
      PackedProduct.codPackedProduct as Material,
      Packaging.codPackaging as CodPackaging,
      Packaging.nbrWeightCoefFromNetToGross as CoefNetBrut
      FROM
      Customer
      INNER JOIN
      CustomerProduct ON Customer.codCustomer = CustomerProduct.codCustomer
      INNER JOIN
      DeliveryPlace ON Customer.codCustomer = DeliveryPlace.codCustomer
      INNER JOIN
      PackedProduct ON CustomerProduct.codPackedProduct = PackedProduct.codPackedProduct
      INNER JOIN
      Product ON PackedProduct.codProduct = Product.codProduct
      INNER JOIN
      Packaging on Packaging.codPackaging = PackedProduct.codPackaging
      WHERE
      (Customer.lblCustomer = @lblCustomer or @lblCustomer IS NULL )
      AND (DeliveryPlace.lblDeliveryplace = @lblDeliveryplace OR @lblDeliveryplace IS NULL)
      AND (PackedProduct.lblPackedProduct = @lblPackedProduct OR @lblPackedProduct IS NULL)


      I need help to understand how can i stop getting my records duplicates.







      sql sql-server tsql






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 20 at 5:37









      Rahul Neekhra

      6021627




      6021627










      asked Nov 20 at 4:59









      Naman

      117




      117
























          1 Answer
          1






          active

          oldest

          votes


















          1














          Could you try this:



          ALTER PROCEDURE [dbo].[psGetClientDropdownResult]   
          @lblCustomer VARCHAR(40),
          @lblDeliveryplace VARCHAR(41),
          @lblPackedProduct VARCHAR(41)
          AS
          BEGIN
          SET NOCOUNT ON;

          SELECT DISTINCT
          Customer.lblCustomer As ClientDestinataire,
          DeliveryPlace.lblDeliveryplace As LieuDeLivraison,
          DeliveryPlace.codCountry AS Pays,
          CustomerProduct.codCustomerProduct As CodeProduitClient,
          CustomerProduct.codCustomerProductColor AS CodeCouleurClient,
          CustomerProduct.codAqp AS AQP,
          DeliveryPlace.codEMSupplier AS CodeFournisseurEMPourClient,
          CustomerProduct.datApplication AS DateDApplication,
          CustomerProduct.codPackedProduct AS Material,
          Product.lblPProduct AS Produit,
          Product.lblProduct AS RefFournisseur,
          PackedProduct.lblPackedProduct AS MaterialDescription,
          Packaging.nbrPackagingNetWeight AS PoidsNet,
          (Packaging.nbrPackagingNetWeight) + (Packaging.nbrAddWeightFromNetToGross) AS PoidsBrut,
          Customer.codCustomer as CodClient,
          PackedProduct.codPackedProduct as Material,
          Packaging.codPackaging as CodPackaging,
          Packaging.nbrWeightCoefFromNetToGross as CoefNetBrut
          FROM
          Customer
          INNER JOIN
          CustomerProduct ON Customer.codCustomer = CustomerProduct.codCustomer
          INNER JOIN
          DeliveryPlace
          ON Customer.codCustomer = DeliveryPlace.codCustomer
          AND CustomerProduct.lblDeliveryplace = DeliveryPlace.lblDeliveryplace
          INNER JOIN
          PackedProduct ON CustomerProduct.codPackedProduct = PackedProduct.codPackedProduct
          INNER JOIN
          Product ON PackedProduct.codProduct = Product.codProduct
          INNER JOIN
          Packaging on Packaging.codPackaging = PackedProduct.codPackaging
          WHERE
          (Customer.lblCustomer = @lblCustomer or @lblCustomer IS NULL )
          AND (DeliveryPlace.lblDeliveryplace = @lblDeliveryplace OR @lblDeliveryplace IS NULL)
          AND (PackedProduct.lblPackedProduct = @lblPackedProduct OR @lblPackedProduct IS NULL)


          The DeliveryPlace must be join using codCustomer and lblDeliveryplace or you will get more rows then needed.



          It will be better if you can normalized your data and move the address in separate table. Then you will be able to join the data using integer column for example.






          share|improve this answer





















          • Its working as expected.
            – Naman
            Nov 20 at 5:56












          • @Naman Does this help?
            – gotqn
            Nov 20 at 6:22










          • @Naman If the answer is working and as expected please click tick mark near answer and make it green
            – Santhana
            Nov 20 at 7:00











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386495%2fhow-to-find-and-remove-duplicates-in-sql-server%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          Could you try this:



          ALTER PROCEDURE [dbo].[psGetClientDropdownResult]   
          @lblCustomer VARCHAR(40),
          @lblDeliveryplace VARCHAR(41),
          @lblPackedProduct VARCHAR(41)
          AS
          BEGIN
          SET NOCOUNT ON;

          SELECT DISTINCT
          Customer.lblCustomer As ClientDestinataire,
          DeliveryPlace.lblDeliveryplace As LieuDeLivraison,
          DeliveryPlace.codCountry AS Pays,
          CustomerProduct.codCustomerProduct As CodeProduitClient,
          CustomerProduct.codCustomerProductColor AS CodeCouleurClient,
          CustomerProduct.codAqp AS AQP,
          DeliveryPlace.codEMSupplier AS CodeFournisseurEMPourClient,
          CustomerProduct.datApplication AS DateDApplication,
          CustomerProduct.codPackedProduct AS Material,
          Product.lblPProduct AS Produit,
          Product.lblProduct AS RefFournisseur,
          PackedProduct.lblPackedProduct AS MaterialDescription,
          Packaging.nbrPackagingNetWeight AS PoidsNet,
          (Packaging.nbrPackagingNetWeight) + (Packaging.nbrAddWeightFromNetToGross) AS PoidsBrut,
          Customer.codCustomer as CodClient,
          PackedProduct.codPackedProduct as Material,
          Packaging.codPackaging as CodPackaging,
          Packaging.nbrWeightCoefFromNetToGross as CoefNetBrut
          FROM
          Customer
          INNER JOIN
          CustomerProduct ON Customer.codCustomer = CustomerProduct.codCustomer
          INNER JOIN
          DeliveryPlace
          ON Customer.codCustomer = DeliveryPlace.codCustomer
          AND CustomerProduct.lblDeliveryplace = DeliveryPlace.lblDeliveryplace
          INNER JOIN
          PackedProduct ON CustomerProduct.codPackedProduct = PackedProduct.codPackedProduct
          INNER JOIN
          Product ON PackedProduct.codProduct = Product.codProduct
          INNER JOIN
          Packaging on Packaging.codPackaging = PackedProduct.codPackaging
          WHERE
          (Customer.lblCustomer = @lblCustomer or @lblCustomer IS NULL )
          AND (DeliveryPlace.lblDeliveryplace = @lblDeliveryplace OR @lblDeliveryplace IS NULL)
          AND (PackedProduct.lblPackedProduct = @lblPackedProduct OR @lblPackedProduct IS NULL)


          The DeliveryPlace must be join using codCustomer and lblDeliveryplace or you will get more rows then needed.



          It will be better if you can normalized your data and move the address in separate table. Then you will be able to join the data using integer column for example.






          share|improve this answer





















          • Its working as expected.
            – Naman
            Nov 20 at 5:56












          • @Naman Does this help?
            – gotqn
            Nov 20 at 6:22










          • @Naman If the answer is working and as expected please click tick mark near answer and make it green
            – Santhana
            Nov 20 at 7:00
















          1














          Could you try this:



          ALTER PROCEDURE [dbo].[psGetClientDropdownResult]   
          @lblCustomer VARCHAR(40),
          @lblDeliveryplace VARCHAR(41),
          @lblPackedProduct VARCHAR(41)
          AS
          BEGIN
          SET NOCOUNT ON;

          SELECT DISTINCT
          Customer.lblCustomer As ClientDestinataire,
          DeliveryPlace.lblDeliveryplace As LieuDeLivraison,
          DeliveryPlace.codCountry AS Pays,
          CustomerProduct.codCustomerProduct As CodeProduitClient,
          CustomerProduct.codCustomerProductColor AS CodeCouleurClient,
          CustomerProduct.codAqp AS AQP,
          DeliveryPlace.codEMSupplier AS CodeFournisseurEMPourClient,
          CustomerProduct.datApplication AS DateDApplication,
          CustomerProduct.codPackedProduct AS Material,
          Product.lblPProduct AS Produit,
          Product.lblProduct AS RefFournisseur,
          PackedProduct.lblPackedProduct AS MaterialDescription,
          Packaging.nbrPackagingNetWeight AS PoidsNet,
          (Packaging.nbrPackagingNetWeight) + (Packaging.nbrAddWeightFromNetToGross) AS PoidsBrut,
          Customer.codCustomer as CodClient,
          PackedProduct.codPackedProduct as Material,
          Packaging.codPackaging as CodPackaging,
          Packaging.nbrWeightCoefFromNetToGross as CoefNetBrut
          FROM
          Customer
          INNER JOIN
          CustomerProduct ON Customer.codCustomer = CustomerProduct.codCustomer
          INNER JOIN
          DeliveryPlace
          ON Customer.codCustomer = DeliveryPlace.codCustomer
          AND CustomerProduct.lblDeliveryplace = DeliveryPlace.lblDeliveryplace
          INNER JOIN
          PackedProduct ON CustomerProduct.codPackedProduct = PackedProduct.codPackedProduct
          INNER JOIN
          Product ON PackedProduct.codProduct = Product.codProduct
          INNER JOIN
          Packaging on Packaging.codPackaging = PackedProduct.codPackaging
          WHERE
          (Customer.lblCustomer = @lblCustomer or @lblCustomer IS NULL )
          AND (DeliveryPlace.lblDeliveryplace = @lblDeliveryplace OR @lblDeliveryplace IS NULL)
          AND (PackedProduct.lblPackedProduct = @lblPackedProduct OR @lblPackedProduct IS NULL)


          The DeliveryPlace must be join using codCustomer and lblDeliveryplace or you will get more rows then needed.



          It will be better if you can normalized your data and move the address in separate table. Then you will be able to join the data using integer column for example.






          share|improve this answer





















          • Its working as expected.
            – Naman
            Nov 20 at 5:56












          • @Naman Does this help?
            – gotqn
            Nov 20 at 6:22










          • @Naman If the answer is working and as expected please click tick mark near answer and make it green
            – Santhana
            Nov 20 at 7:00














          1












          1








          1






          Could you try this:



          ALTER PROCEDURE [dbo].[psGetClientDropdownResult]   
          @lblCustomer VARCHAR(40),
          @lblDeliveryplace VARCHAR(41),
          @lblPackedProduct VARCHAR(41)
          AS
          BEGIN
          SET NOCOUNT ON;

          SELECT DISTINCT
          Customer.lblCustomer As ClientDestinataire,
          DeliveryPlace.lblDeliveryplace As LieuDeLivraison,
          DeliveryPlace.codCountry AS Pays,
          CustomerProduct.codCustomerProduct As CodeProduitClient,
          CustomerProduct.codCustomerProductColor AS CodeCouleurClient,
          CustomerProduct.codAqp AS AQP,
          DeliveryPlace.codEMSupplier AS CodeFournisseurEMPourClient,
          CustomerProduct.datApplication AS DateDApplication,
          CustomerProduct.codPackedProduct AS Material,
          Product.lblPProduct AS Produit,
          Product.lblProduct AS RefFournisseur,
          PackedProduct.lblPackedProduct AS MaterialDescription,
          Packaging.nbrPackagingNetWeight AS PoidsNet,
          (Packaging.nbrPackagingNetWeight) + (Packaging.nbrAddWeightFromNetToGross) AS PoidsBrut,
          Customer.codCustomer as CodClient,
          PackedProduct.codPackedProduct as Material,
          Packaging.codPackaging as CodPackaging,
          Packaging.nbrWeightCoefFromNetToGross as CoefNetBrut
          FROM
          Customer
          INNER JOIN
          CustomerProduct ON Customer.codCustomer = CustomerProduct.codCustomer
          INNER JOIN
          DeliveryPlace
          ON Customer.codCustomer = DeliveryPlace.codCustomer
          AND CustomerProduct.lblDeliveryplace = DeliveryPlace.lblDeliveryplace
          INNER JOIN
          PackedProduct ON CustomerProduct.codPackedProduct = PackedProduct.codPackedProduct
          INNER JOIN
          Product ON PackedProduct.codProduct = Product.codProduct
          INNER JOIN
          Packaging on Packaging.codPackaging = PackedProduct.codPackaging
          WHERE
          (Customer.lblCustomer = @lblCustomer or @lblCustomer IS NULL )
          AND (DeliveryPlace.lblDeliveryplace = @lblDeliveryplace OR @lblDeliveryplace IS NULL)
          AND (PackedProduct.lblPackedProduct = @lblPackedProduct OR @lblPackedProduct IS NULL)


          The DeliveryPlace must be join using codCustomer and lblDeliveryplace or you will get more rows then needed.



          It will be better if you can normalized your data and move the address in separate table. Then you will be able to join the data using integer column for example.






          share|improve this answer












          Could you try this:



          ALTER PROCEDURE [dbo].[psGetClientDropdownResult]   
          @lblCustomer VARCHAR(40),
          @lblDeliveryplace VARCHAR(41),
          @lblPackedProduct VARCHAR(41)
          AS
          BEGIN
          SET NOCOUNT ON;

          SELECT DISTINCT
          Customer.lblCustomer As ClientDestinataire,
          DeliveryPlace.lblDeliveryplace As LieuDeLivraison,
          DeliveryPlace.codCountry AS Pays,
          CustomerProduct.codCustomerProduct As CodeProduitClient,
          CustomerProduct.codCustomerProductColor AS CodeCouleurClient,
          CustomerProduct.codAqp AS AQP,
          DeliveryPlace.codEMSupplier AS CodeFournisseurEMPourClient,
          CustomerProduct.datApplication AS DateDApplication,
          CustomerProduct.codPackedProduct AS Material,
          Product.lblPProduct AS Produit,
          Product.lblProduct AS RefFournisseur,
          PackedProduct.lblPackedProduct AS MaterialDescription,
          Packaging.nbrPackagingNetWeight AS PoidsNet,
          (Packaging.nbrPackagingNetWeight) + (Packaging.nbrAddWeightFromNetToGross) AS PoidsBrut,
          Customer.codCustomer as CodClient,
          PackedProduct.codPackedProduct as Material,
          Packaging.codPackaging as CodPackaging,
          Packaging.nbrWeightCoefFromNetToGross as CoefNetBrut
          FROM
          Customer
          INNER JOIN
          CustomerProduct ON Customer.codCustomer = CustomerProduct.codCustomer
          INNER JOIN
          DeliveryPlace
          ON Customer.codCustomer = DeliveryPlace.codCustomer
          AND CustomerProduct.lblDeliveryplace = DeliveryPlace.lblDeliveryplace
          INNER JOIN
          PackedProduct ON CustomerProduct.codPackedProduct = PackedProduct.codPackedProduct
          INNER JOIN
          Product ON PackedProduct.codProduct = Product.codProduct
          INNER JOIN
          Packaging on Packaging.codPackaging = PackedProduct.codPackaging
          WHERE
          (Customer.lblCustomer = @lblCustomer or @lblCustomer IS NULL )
          AND (DeliveryPlace.lblDeliveryplace = @lblDeliveryplace OR @lblDeliveryplace IS NULL)
          AND (PackedProduct.lblPackedProduct = @lblPackedProduct OR @lblPackedProduct IS NULL)


          The DeliveryPlace must be join using codCustomer and lblDeliveryplace or you will get more rows then needed.



          It will be better if you can normalized your data and move the address in separate table. Then you will be able to join the data using integer column for example.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 at 5:47









          gotqn

          19.6k32111189




          19.6k32111189












          • Its working as expected.
            – Naman
            Nov 20 at 5:56












          • @Naman Does this help?
            – gotqn
            Nov 20 at 6:22










          • @Naman If the answer is working and as expected please click tick mark near answer and make it green
            – Santhana
            Nov 20 at 7:00


















          • Its working as expected.
            – Naman
            Nov 20 at 5:56












          • @Naman Does this help?
            – gotqn
            Nov 20 at 6:22










          • @Naman If the answer is working and as expected please click tick mark near answer and make it green
            – Santhana
            Nov 20 at 7:00
















          Its working as expected.
          – Naman
          Nov 20 at 5:56






          Its working as expected.
          – Naman
          Nov 20 at 5:56














          @Naman Does this help?
          – gotqn
          Nov 20 at 6:22




          @Naman Does this help?
          – gotqn
          Nov 20 at 6:22












          @Naman If the answer is working and as expected please click tick mark near answer and make it green
          – Santhana
          Nov 20 at 7:00




          @Naman If the answer is working and as expected please click tick mark near answer and make it green
          – Santhana
          Nov 20 at 7:00


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53386495%2fhow-to-find-and-remove-duplicates-in-sql-server%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

          Alcedinidae

          RAC Tourist Trophy