Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. need query to calculate amount

need query to calculate amount

Scheduled Pinned Locked Moved C#
databasesales
7 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    harithadotnet
    wrote on last edited by
    #1

    Hi, I have a table like Sno ReceiptNo CustomerId Amount Date commissionAmount AgentId 1 10 C96 5000 02/02/2009 500 A20 2 10 C96 5000 02/02/2009 300 A46 3 10 C96 5000 02/02/2009 200 A37 4 11 C50 3000 02/03/2009 300 A35 5 11 C96 2000 02/03/2009 200 A43 here one receiptid have multiple records with same customer. this table contains multiple records with the same receiptno and customer id.but i want to add distinct amount of each receipt of perticular custimer. means here customer C96 total paid amount is 5000+2000 i.e 7000. I want query for this.If any one give the answer it will be very useful for me . Thanks in advance. Haritha.

    Haritha

    N M M P P 5 Replies Last reply
    0
    • H harithadotnet

      Hi, I have a table like Sno ReceiptNo CustomerId Amount Date commissionAmount AgentId 1 10 C96 5000 02/02/2009 500 A20 2 10 C96 5000 02/02/2009 300 A46 3 10 C96 5000 02/02/2009 200 A37 4 11 C50 3000 02/03/2009 300 A35 5 11 C96 2000 02/03/2009 200 A43 here one receiptid have multiple records with same customer. this table contains multiple records with the same receiptno and customer id.but i want to add distinct amount of each receipt of perticular custimer. means here customer C96 total paid amount is 5000+2000 i.e 7000. I want query for this.If any one give the answer it will be very useful for me . Thanks in advance. Haritha.

      Haritha

      N Offline
      N Offline
      Najmal
      wrote on last edited by
      #2

      HI Haritha......... SELECT SUM(amount) FROM customer WHERE ReciptNo IN (SELECT DISTINCT ReceiptNo,amount FROM customer WHERE CustomerId='C96') :rose:najmalccl@gmail.com

      1 Reply Last reply
      0
      • H harithadotnet

        Hi, I have a table like Sno ReceiptNo CustomerId Amount Date commissionAmount AgentId 1 10 C96 5000 02/02/2009 500 A20 2 10 C96 5000 02/02/2009 300 A46 3 10 C96 5000 02/02/2009 200 A37 4 11 C50 3000 02/03/2009 300 A35 5 11 C96 2000 02/03/2009 200 A43 here one receiptid have multiple records with same customer. this table contains multiple records with the same receiptno and customer id.but i want to add distinct amount of each receipt of perticular custimer. means here customer C96 total paid amount is 5000+2000 i.e 7000. I want query for this.If any one give the answer it will be very useful for me . Thanks in advance. Haritha.

        Haritha

        M Offline
        M Offline
        Muhammad Shahid Farooq
        wrote on last edited by
        #3

        Haritha, use the following query this will help you: Select sum(Amount) as Amount_Sum from Customer group by CustomerId

        1 Reply Last reply
        0
        • H harithadotnet

          Hi, I have a table like Sno ReceiptNo CustomerId Amount Date commissionAmount AgentId 1 10 C96 5000 02/02/2009 500 A20 2 10 C96 5000 02/02/2009 300 A46 3 10 C96 5000 02/02/2009 200 A37 4 11 C50 3000 02/03/2009 300 A35 5 11 C96 2000 02/03/2009 200 A43 here one receiptid have multiple records with same customer. this table contains multiple records with the same receiptno and customer id.but i want to add distinct amount of each receipt of perticular custimer. means here customer C96 total paid amount is 5000+2000 i.e 7000. I want query for this.If any one give the answer it will be very useful for me . Thanks in advance. Haritha.

          Haritha

          M Offline
          M Offline
          Member 4501940
          wrote on last edited by
          #4

          Either of these will work if using sql server

          with temp (ReceiptNo, CustomerID, Amount)
          as
          (
          SELECT ReceiptNo, CustomerID, Amount
          FROM customer
          group by ReceiptNo, CustomerID, Amount
          )
          select CustomerID, sum(Amount) from temp group by CustomerID
          GO

          /*** or this one ***/

          SELECT ReceiptNo, CustomerID, Amount
          INTO [#temp]
          FROM customer
          GROUP BY ReceiptNo, CustomerID, Amount
          select CustomerID, sum(Amount) from #temp group by CustomerID
          GO

          drop table #temp
          GO

          P 1 Reply Last reply
          0
          • H harithadotnet

            Hi, I have a table like Sno ReceiptNo CustomerId Amount Date commissionAmount AgentId 1 10 C96 5000 02/02/2009 500 A20 2 10 C96 5000 02/02/2009 300 A46 3 10 C96 5000 02/02/2009 200 A37 4 11 C50 3000 02/03/2009 300 A35 5 11 C96 2000 02/03/2009 200 A43 here one receiptid have multiple records with same customer. this table contains multiple records with the same receiptno and customer id.but i want to add distinct amount of each receipt of perticular custimer. means here customer C96 total paid amount is 5000+2000 i.e 7000. I want query for this.If any one give the answer it will be very useful for me . Thanks in advance. Haritha.

            Haritha

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            Why do these look like sports bookmaking[^] transactions? :suss:

            1 Reply Last reply
            0
            • M Member 4501940

              Either of these will work if using sql server

              with temp (ReceiptNo, CustomerID, Amount)
              as
              (
              SELECT ReceiptNo, CustomerID, Amount
              FROM customer
              group by ReceiptNo, CustomerID, Amount
              )
              select CustomerID, sum(Amount) from temp group by CustomerID
              GO

              /*** or this one ***/

              SELECT ReceiptNo, CustomerID, Amount
              INTO [#temp]
              FROM customer
              GROUP BY ReceiptNo, CustomerID, Amount
              select CustomerID, sum(Amount) from #temp group by CustomerID
              GO

              drop table #temp
              GO

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              Why the H are you using temporary tables for that? :confused:

              1 Reply Last reply
              0
              • H harithadotnet

                Hi, I have a table like Sno ReceiptNo CustomerId Amount Date commissionAmount AgentId 1 10 C96 5000 02/02/2009 500 A20 2 10 C96 5000 02/02/2009 300 A46 3 10 C96 5000 02/02/2009 200 A37 4 11 C50 3000 02/03/2009 300 A35 5 11 C96 2000 02/03/2009 200 A43 here one receiptid have multiple records with same customer. this table contains multiple records with the same receiptno and customer id.but i want to add distinct amount of each receipt of perticular custimer. means here customer C96 total paid amount is 5000+2000 i.e 7000. I want query for this.If any one give the answer it will be very useful for me . Thanks in advance. Haritha.

                Haritha

                P Offline
                P Offline
                priyareguri
                wrote on last edited by
                #7

                select distinct receiptno from tablename... i will displays all records without duplicates then u can fine total amount of all records ...or particular customer records...

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups