Solved

Muliplication of two columns

Posted on 2010-09-22
9
358 Views
Last Modified: 2013-11-28
Hi,
I am generating a report from access using sql query. Attached is query. However, the retrives only three columns they are

Entered Invoices
EMS Line Item
No of Errors

I need two more columns named “DPMO*16” and “DPMO*8”.  “DPMO*16” column value is the multiplication on “Entered Invoices” value * 16 and “DPMO*8” column value is the multiplication on “EMS Line Item” value * 8. Also, I require the sum of “DPMO*16” and “DPMO*8”.
I have attached the excel file for your better understanding.

Please help me. I have also attached the current sql query. Please help me on this.

Regards,
Prashanth

strSQL = "DELETE FROM SummaryReport"
CurrentDb.Execute strSQL
strSQL = "INSERT INTO SummaryReport ( Clients, [Entered Invoices], [EMS Line Item], [No Of Errors] ) " _
& "SELECT ClientName.ClientName AS Clients, Count(QCLog.Noli) AS [Entered Invoices], " _
& "Sum(QCLog.Noli) AS [EMS Line Item], Sum(QCLog.NumofErr) as [No of Errors] " _
& "FROM ClientName LEFT JOIN QCLog ON ClientName.ClientName = QCLog.ClientName " _
& " WHERE (([QCLog].[CheckedDate]) >=  # " & st1 & " #) AND (([QCLog].[CheckedDate]) <=  # " & st2 & " #) GROUP BY ClientName.ClientName;"
CurrentDb.Execute strSQL
On Error GoTo errorhandler
DoCmd.SetWarnings False
DoCmd.OutputTo acOutputTable, "SummaryReport", acFormatXLS

Open in new window

SummaryReport.xls
0
Comment
Question by:pg1533
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 7

Expert Comment

by:klakkas
ID: 33732508
Add these 3 lines in your select:
& " Count(QCLog.Noli) * 16 AS [DPMO_16], " _
& " Count(QCLog.Noli) * 8 AS [DPMO_8], " _
& " (Count(QCLog.Noli) * 16) + (Count(QCLog.Noli) * 8) AS [TotalDPMO], " _

The total query should be:
strSQL = "INSERT INTO SummaryReport ( Clients, [Entered Invoices], [EMS Line Item], [No Of Errors] ) " _
& "SELECT ClientName.ClientName AS Clients, Count(QCLog.Noli) AS [Entered Invoices], " _
& "Sum(QCLog.Noli) AS [EMS Line Item], Sum(QCLog.NumofErr) as [No of Errors], " _
& " Count(QCLog.Noli) * 16 AS [DPMO_16], " _
& " Count(QCLog.Noli) * 8 AS [DPMO_8], " _
& " (Count(QCLog.Noli) * 16) + (Count(QCLog.Noli) * 8) AS [TotalDPMO], " _
& "FROM ClientName LEFT JOIN QCLog ON ClientName.ClientName = QCLog.ClientName " _
& " WHERE (([QCLog].[CheckedDate]) >=  # " & st1 & " #) AND (([QCLog].[CheckedDate]) <=  # " & st2 & " #) GROUP BY ClientName.ClientName;"
CurrentDb.Execute strSQL
0
 
LVL 7

Expert Comment

by:klakkas
ID: 33732516
!!!! Correction. DPMO_8 is incorrect

This is the correct response:

Add these 3 lines in your select:
& " Count(QCLog.Noli) * 16 AS [DPMO_16], " _
& " Sum(QCLog.Noli) * 8 AS [DPMO_8], " _
& " (Count(QCLog.Noli) * 16) + (Sum(QCLog.Noli) * 8) AS [TotalDPMO], " _

The total query should be:
strSQL = "INSERT INTO SummaryReport ( Clients, [Entered Invoices], [EMS Line Item], [No Of Errors] ) " _
& "SELECT ClientName.ClientName AS Clients, Count(QCLog.Noli) AS [Entered Invoices], " _
& "Sum(QCLog.Noli) AS [EMS Line Item], Sum(QCLog.NumofErr) as [No of Errors], " _
& " Count(QCLog.Noli) * 16 AS [DPMO_16], " _
& " Sum(QCLog.Noli) * 8 AS [DPMO_8], " _
& " (Count(QCLog.Noli) * 16) + (Sum(QCLog.Noli) * 8) AS [TotalDPMO], " _
& "FROM ClientName LEFT JOIN QCLog ON ClientName.ClientName = QCLog.ClientName " _
& " WHERE (([QCLog].[CheckedDate]) >=  # " & st1 & " #) AND (([QCLog].[CheckedDate]) <=  # " & st2 & " #) GROUP BY ClientName.ClientName;"
CurrentDb.Execute strSQL
0
 
LVL 11

Expert Comment

by:JoeNuvo
ID: 33732701
a little correction to klakkas

don't forget to add more field lists into INSERT INTO part

INSERT INTO SummaryReport (Clients, [Entered Invoices], [EMS Line Item], [No Of Errors] , [DPMO*16] , [DPMO*8], [TotalDPMO] )
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:pg1533
ID: 33733115
Hi, I am getting this error

"Number of query values and destination fields are not the same"

Please advice
0
 

Author Comment

by:pg1533
ID: 33733122
I have attached the code snippet
strSQL = "DELETE FROM SummaryReport"
CurrentDb.Execute strSQL

strSQL = "INSERT INTO SummaryReport ( Clients, [Entered Invoices], [EMS Line Item], [No Of Errors], [DPMO*16] , [DPMO*8], [TotalDPMO] ) " _
& "SELECT ClientName.ClientName AS Clients, Count(QCLog.Noli) AS [Entered Invoices], " _
& "Sum(QCLog.Noli) AS [EMS Line Item], Sum(QCLog.NumofErr) as [No of Errors] " _
& " Count(QCLog.Noli) * 16 AS [DPMO*16], " _
& " Count(QCLog.Noli) * 8 AS [DPMO*8], " _
& " (Count(QCLog.Noli) * 16) + (Count(QCLog.Noli) * 8) AS [TotalDPMO], " _
& " FROM ClientName LEFT JOIN QCLog ON ClientName.ClientName = QCLog.ClientName " _
& " WHERE (([QCLog].[CheckedDate]) >=  # " & st1 & " #) AND (([QCLog].[CheckedDate]) <=  # " & st2 & " #) GROUP BY ClientName.ClientName;"


CurrentDb.Execute strSQL
On Error GoTo errorhandler

Open in new window

0
 
LVL 7

Expert Comment

by:klakkas
ID: 33733134
You must do as JoeNuvo suggested.
The correct query is this:

strSQL = "INSERT INTO SummaryReport ( Clients, [Entered Invoices], [EMS Line Item], [No Of Errors] " _
& "[DPMO_16], [DPMO_8], [TotalDPMO]) " _
& "SELECT ClientName.ClientName AS Clients, Count(QCLog.Noli) AS [Entered Invoices], " _
& "Sum(QCLog.Noli) AS [EMS Line Item], Sum(QCLog.NumofErr) as [No of Errors], " _
& " Count(QCLog.Noli) * 16 AS [DPMO_16], " _
& " Sum(QCLog.Noli) * 8 AS [DPMO_8], " _
& " (Count(QCLog.Noli) * 16) + (Sum(QCLog.Noli) * 8) AS [TotalDPMO], " _
& "FROM ClientName LEFT JOIN QCLog ON ClientName.ClientName = QCLog.ClientName " _
& " WHERE (([QCLog].[CheckedDate]) >=  # " & st1 & " #) AND (([QCLog].[CheckedDate]) <=  # " & st2 & " #) GROUP BY ClientName.ClientName;"
0
 
LVL 7

Expert Comment

by:klakkas
ID: 33733150
Sorry friend, the problem is an extra ',' afther [TotalDPMO] in line 9 or your code, right before the FROM keyword.
0
 
LVL 7

Accepted Solution

by:
klakkas earned 500 total points
ID: 33733158
Full query:

strSQL = "INSERT INTO SummaryReport ( Clients, [Entered Invoices], [EMS Line Item], [No Of Errors] " _
& "[DPMO_16], [DPMO_8], [TotalDPMO]) " _
& "SELECT ClientName.ClientName AS Clients, Count(QCLog.Noli) AS [Entered Invoices], " _
& "Sum(QCLog.Noli) AS [EMS Line Item], Sum(QCLog.NumofErr) as [No of Errors], " _
& " Count(QCLog.Noli) * 16 AS [DPMO_16], " _
& " Sum(QCLog.Noli) * 8 AS [DPMO_8], " _
& " (Count(QCLog.Noli) * 16) + (Sum(QCLog.Noli) * 8) AS [TotalDPMO] " _
& "FROM ClientName LEFT JOIN QCLog ON ClientName.ClientName = QCLog.ClientName " _
& " WHERE (([QCLog].[CheckedDate]) >=  # " & st1 & " #) AND (([QCLog].[CheckedDate]) <=  # " & st2 & " #) GROUP BY ClientName.ClientName;"
0
 

Author Closing Comment

by:pg1533
ID: 33733248
Got It
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question