Solved

Muliplication of two columns

Posted on 2010-09-22
9
352 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

777 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