Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 361
  • Last Modified:

Muliplication of two columns

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
pg1533
Asked:
pg1533
  • 5
  • 3
1 Solution
 
klakkasCommented:
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
 
klakkasCommented:
!!!! 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
 
JoeNuvoCommented:
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
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
pg1533Author Commented:
Hi, I am getting this error

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

Please advice
0
 
pg1533Author Commented:
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
 
klakkasCommented:
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
 
klakkasCommented:
Sorry friend, the problem is an extra ',' afther [TotalDPMO] in line 9 or your code, right before the FROM keyword.
0
 
klakkasCommented:
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
 
pg1533Author Commented:
Got It
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now