Solved

Muliplication of two columns

Posted on 2010-09-22
9
350 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
  • 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
 

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Viewers will learn how the fundamental information of how to create a table.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now