Access 2003 SQL Syntax error - sql

I am new with access 2003 and been stuck on this query I have wrote for a while now. The tables and column names, operators and brackets i believe are all correct however I am getting a syntax error only after I inserted the following join operation
FROM (tDailyEntries
INNER JOIN tLEDGERS ON tLEDGERS.Action = tDailyEntries.ActionNo)
INNER JOIN (tProjects
below is my full code
SELECT DISTINCT tProjects.CC_IO AS ProjectNo,
Year([DateFrom]) & " Accrual " & MonthName(Month([DateFrom])) & " - "+[CompanyName] & " ( "+([LastName]) & ")" AS [Line/Item/Text],
tUsers.LastName AS Last_Name,
tDailyEntries.UserId AS UserID,
contractordailyrate AS DailyRate,
contractordailyhours AS Hours,
ROUND(contractordailyrate / contractordailyhours, 2) AS HourlyRate,
ROUND(SUM(tDailyEntries.CalculatedDailyHours), 2) AS MonthlyHours,
ROUND((HourlyRate * MonthlyHours), 2) AS Charge,
ROUND(Charge+ROUND((Charge*0.2),2),2) AS Accruals, tProjects.Project AS Project
FROM (tDailyEntries
INNER JOIN tLEDGERS ON tLEDGERS.Action = tDailyEntries.ActionNo)
INNER JOIN (tProjects
RIGHT JOIN (textcontractor
RIGHT JOIN (tTitle
RIGHT JOIN ((Location
RIGHT JOIN (tDepartments
RIGHT JOIN tUsers
ON tProjectType.ProjectTypeID = tProjects.ProjectTypeID)
ON tDepartments.DeptID = tUsers.DeptID)
ON tLocation.LocationID = tUsers.LocationID)
RIGHT JOIN (((tDailyEntries
LEFT JOIN tDepartments AS tDepartments_1
ON tDailyEntries.DeptCharged = tDepartments_1.DeptShortName)
LEFT JOIN tActions ON tDailyEntries.ActionNo = tActions.ActionID)
LEFT JOIN tLookups
ON tDailyEntries.Zone = tLookups.LookupID)
ON tUsers.UserID = tDailyEntries.UserID)
LEFT JOIN textmain
ON tUsers.UserID = textmain.userID)
ON tTitle.TitleID = tUsers.TitleID)
ON textcontractor.companyid = textmain.contractorcompany)
ON tProjects.ProjectID = tDailyEntries.ProjectNo
WHERE tTitle.TitleID = 37
AND Month([DateFrom]) = MonthNum
AND Day([DateFrom]) <21
GROUP BY tProjects.CC_IO, Year([DateFrom]) & " Accrual " & MonthName(Month([DateFrom])) & " - "+[CompanyName] & " ( "+([LastName]) & ")", tUsers.LastName, tDailyEntries.UserId, textmain.contractordailyrate,
Month([DateFrom]), textmain.contractordailyhours, tProjects.Project;
Any help would be great.

Related

I have A problem with dividing the value of 0 by 0 in an Access database

When I try to extract the result of Division 2 Field from table in access database
If I have a value of 0 an error occurs
sqlSTR = "SELECT TBL_Category_Item_File.Item_Org_Price2/TBL_Stocks_Balances.Item_QTY AS ['Price']FROM (((TBL_Category_Item_File INNER JOIN TBL_Suppliers_Product ON TBL_Category_Item_File.Item_ID = TBL_Suppliers_Product.Item_ID) INNER JOIN TBL_Suppliers ON TBL_Suppliers_Product.Supp_ID = TBL_Suppliers.Supp_ID) INNER JOIN TBL_Sub_categories ON TBL_Category_Item_File.ID_Sub_categories = TBL_Sub_categories.ID_Sub_categories) INNER JOIN TBL_Stocks_Balances ON (TBL_Stocks_Balances.Item_ID = TBL_Category_Item_File.Item_ID) AND (TBL_Category_Item_File.Item_BarCode = TBL_Stocks_Balances.Item_Barcode) WHERE tbl_Category_Item_File.Catg_ID =" & Split(cmblist.Text, " - ")(0)
If you are trying to avoid the error, you can use a CASE statement in your query to check for a 0 value in the Item_Org_Price2 field and return a different value if it is 0. For example, you could do something like this:
SELECT
CASE
WHEN TBL_Category_Item_File.Item_Org_Price2 = 0
THEN 0
ELSE TBL_Category_Item_File.Item_Org_Price2/TBL_Stocks_Balances.Item_QTY
END AS ['Price']
FROM (((TBL_Category_Item_File INNER JOIN TBL_Suppliers_Product ON TBL_Category_Item_File.Item_ID = TBL_Suppliers_Product.Item_ID) INNER JOIN TBL_Suppliers ON TBL_Suppliers_Product.Supp_ID = TBL_Suppliers.Supp_ID) INNER JOIN TBL_Sub_categories ON TBL_Category_Item_File.ID_Sub_categories = TBL_Sub_categories.ID_Sub_categories) INNER JOIN TBL_Stocks_Balances ON (TBL_Stocks_Balances.Item_ID = TBL_Category_Item_File.Item_ID) AND (TBL_Category_Item_File.Item_BarCode = TBL_Stocks_Balances.Item_Barcode) WHERE tbl_Category_Item_File.Catg_ID =" & Split(cmblist.Text, " - ")(0)

Unable to convert SQL to JPQL

I am trying to convert following Oracle SQL (which works)
select sum(ct.some_count) from TABLE1 mc
inner join TABLE2 xref on mc.cnum = xref.cnum
inner join TABLE3 ct on xref.srt = ct.srt
inner join TABLE4 pc on pc.id = xref.id
where mc.CARD_NO = '111' and pc.code = '222';
To following JPQL.
#Query("SELECT sum(ct.someCount) FROM Table1Entity mc " +
"inner join TABLE2Entity xref on mc.cnum = xref.cnum " +
"inner join TABLE3Entity ct on xref.srt = ct.srt " +
"inner join TABLE4Entity pc on pc.id = xref.id " +
"where mc.CARD_NO = :cardNumber and pc.code = :code")
long getTotalCount(#Param("cardNumber") String cardNumber, #Param("code") String code);
I am getting the following Exception.
QuerySyntaxException: unexpected token
Can I please get some help on what I am doing wrong?
I am using Spring and this is my Repository for this Query.
#Repository(value = "someCountRepository")
public interface SomeCountRepository extends JpaRepository<Table3Entity, TableId> {
#Query("SELECT sum(ct.someCount) FROM Table1Entity mc " +
"inner join TABLE2Entity xref on mc.cnum = xref.cnum " +
"inner join TABLE3Entity ct on xref.srt = ct.srt " +
"inner join TABLE4Entity pc on pc.id = xref.id " +
"where mc.CARD_NO = :cardNumber and pc.code = :code")
long getTotalCount(#Param("cardNumber") String cardNumber, #Param("code") String code);
}
#Query("SELECT sum(ct.someCount) FROM Table1Entity mc " +
"inner join TABLE2Entity xref on mc.cnum = xref.cnum " +
"inner join TABLE3Entity ct on xref.srt = ct.srt " +
"inner join TABLE4Entity pc on pc.id = xref.id " +
"where mc.CARD_NO = :cardNumber and pc.code = :code",
nativeQuery = true) // set native query to true
long getTotalCount(#Param("cardNumber") String cardNumber, #Param("code") String code);
Since you are copy the query exactly from Oracle SQL which is not JPQL, then you should declare it as native query.
References : Spring Data JPA #Query #2.2. Native

CASE in WHERE Clause SQL VBA Excel

I am trying to add a filter criteria for the current fiscal year in a WHERE statement in my code. However, I don't know how to integrate the CASE statement in my WHERE clause in VBA. Here's the code that I am working on:
Source = "SELECT tblretirements.retirementID As `RetirementID`,tblretirements.InputBy As `Input By`, tblretirements.ReceiptDate As `Date Received` , tblretirements.FirstName As `First Name`, tblretirements.LastName As `Last Name`, tblretirements.DateOfBirth As `DOB`, tblretirements.DateOfRetirement As `Retirement Date`, tblBenefitInProcress.RetirementDescription As `Retirement Type`, tblretirements.MemberPIN As `Pin`, tblcurrentplan.CurrentPlan As `Current Plan`, tblretirements.ServiceCredits As `Service Crdits w/o PS/AC`, tblretirements.MultiplePlans As `Multiple Plans/Tiers?`, " & _
" tblretirements.ConfirmationLetterMailed As `Mailed Confirm Letter`, tblretirements.WorkbookSetup As `Set Up Excel Workbook`, tblCalculationTeam.CalcTeam As `Calculation Team`, tblCalculationPersonnel.Name As `Assigned Staff`, tblretirements.ReviewDate As`Review Date`, tblBoardStatus.StatusReported As`BoardStatusID`, tblretirements.ReciprocityID As `Reciprocity?`, tblretirements.EmployerCodeID As `Employer`, " & _
" tblDepartment.DepartmentName As `Department`, tblretirements.PendingPurchase As `Pending Purchase(s)?`, tblJoinder.Joinder As `Joinder or Pending DRO?`, tblDisabilityPending.AgendaDisability As `DisabilityID`, tblReciprocity.ReciprocalStatus, tblOrientationStatus.OrientationStatus As `Orientation Elected?`,tblretirements.OrientationDate As `Orientation Date`, tblReviewPersonnel.ReviewerName As `Designated Reviewer`, tblretirements.FileSetupApproved As `File Set-Up Approved`, tblretirements.AgendaApplication As `Agenda Application`, tblretirements.EstimateToReviewer As `Estimate to Reviewer`, tblretirements.EstimateToSupervisor As `Estimate to Supervisor`, " & _
" tblretirements.EstimateApproved As `Estimate Approved`, tblretirements.FinalPaycheck As `Final Paycheck Date`, tblretirements.FinalService As `Final Service with PS/AC`, tblretirements.FinalToReviewer As `Final Calc to Reviewer`, tblretirements.FinalToSupervisor As `Final Calc to Supervisor`, tblretirements.FinalApproved As `Final Calc Approved`, tblretirements.ApplicationCancelled As `App Cancelled by Member?`, tblretirements.RetElectionDistributed As `Retirement Election Distributed`, tblretirements.RetElectionReturned As `Retirement Election Returned`, tblPaymentOption.AgendaOption As `Option/Payment Selected`, " & _
" tblretirements.TempAnnuityID As `Age Request for Temp Annuity`, tblretirements.FinalAllowance As `Final Allowance Calculation`, tblretirements.Continuance As `Continuance`, tblretirements.PayrollFormsStaff As `Payroll Forms Completed (Staff)`, tblretirements.AgendaPayment As `Option-Payment`, tblretirements.PayrollFormsSupervisor As `Payroll Forms Reviewed (Supv)`, " & _
" tblretirements.CboApprovedAllowance As `Allowance Approved (CBO)`, tblretirements.AllowanceEstimated As `Allowance Estimated?`, tblretirements.AllowEnteredInPayroll As `Allowance Entered In Payroll`, tblretirements.DistributionCycleID As `Distribution Cycle for 1st Payment`, " & _
" tblretirements.FirstPayDate As `Distribution Date for 1st Payment`, tblretirements.AllowanceFinalized As `Allowance Finalized`, tblretirements.FileImaged As `Retirement File Imaged`" & _
" FROM ((((((((((((tblRetirements " & _
" LEFT JOIN tblCalculationPersonnel On tblRetirements.CoordinatorID=tblCalculationPersonnel.CoordinatorID) " & _
" LEFT JOIN tblCurrentPlan On tblRetirements.CurrentPlanID=tblCurrentPlan.CurrentPlanID) " & _
" LEFT JOIN tblBenefitInProcress On tblRetirements.BenefitInProcess=tblBenefitInProcress.RetirementTypeID) " & _
" LEFT JOIN tblPaymentOption ON tblretirements.OptionID=tblPaymentoption.OptionID) " & _
" LEFT JOIN tblReviewPersonnel ON tblretirements.ReviewerID=tblReviewPersonnel.ReviewerID) " & _
" LEFT JOIN tblOrientationStatus ON tblretirements.OrientationID=tblOrientationStatus.OrientationID) " & _
" LEFT JOIN tblDisabilityPending ON tblretirements.DisabilityID=tblDisabilityPending.DisabilityID) " & _
" LEFT JOIN tblJoinder ON tblretirements.JoinderID=tblJoinder.JoinderID) " & _
" LEFT JOIN tblDepartment ON tblretirements.DepartmentID=tblDepartment.DepartmentID) " & _
" LEFT JOIN tblEmployerCode ON tblretirements.EmployerCodeID=tblEmployerCode.EmployerCodeID) " & _
" LEFT JOIN tblReciprocity ON tblretirements.ReciprocityID=tblReciprocity.ReciprocityID) " & _
" LEFT JOIN tblCalculationTeam ON tblretirements.CalculationTeamID=tblCalculationTeam.CalculationTeamID) " & _
" LEFT JOIN tblBoardStatus ON tblretirements.BoardStatusID=tblBoardStatus.BoardStatusID " & _
This is what I need assistance with:
" WHERE tblretirements.ApplicationCancelled = 'No' AND (tblretirements.ReceiptDate IS NULL OR tblretirements.ReceiptDate " & _
" BETWEEN (CASE WHEN MONTH(getdate()) < 7 THEN DATEFROMPARTS(YEAR(getdate())-1,7,1) " & _
" ELSE DATEFROMPARTS(YEAR(getdate()),7,1) End ) AND (CASE WHEN MONTH(getdate()) < 7 THEN DATEFROMPARTS(YEAR(getdate()),6,30) " & _
" ELSE DATEFROMPARTS(YEAR(getdate())+1,6,30)End )) "
Can someone please help me? Thank you.
Several issues need attention here:
For complex queries of many joins, do not build SQL on the fly during application code. Save it as stored object in MS Access so the engine can save best execution plan. Then have application, here being Excel, reference the query by name. You can even pass values as parameters to a saved query.
Use table aliases to avoid writing out the long table names for a more readable and maintainable, and less lengthy query.
No two SQL dialects are the same. Even under the same vendor, here being Microsoft. The JET/ACE SQL (Windows .dll files) dialect that MS Access uses is different than the T-SQL dialect that SQL Server uses. Interestingly, another database, Sybase, also uses T-SQL with a history to why.
But like all other dialects (e.g., Oracle, Postgres) though, both share most traditional ANSI SQL functions which is the standard of the language. Therefore, SQL Server's CASE, DATEFROMPARTS(), and GETDATE() must be replaced for Access' IIF(), DATESERIAL(), and DATE(). Interestingly though, CASE is an ANSI method.
Consider the following re-write of your query and specifically the WHERE clause to be saved in MS Access as a stored object.
SQL
SELECT r.retirementid AS `RetirementID`,
r.inputby AS `Input By`,
r.receiptdate AS `Date Received`,
r.firstname AS `First Name`,
r.lastname AS `Last Name`,
r.dateofbirth AS `DOB`,
r.dateofretirement AS `Retirement Date`,
bp.retirementdescription AS `Retirement Type`,
r.memberpin AS `Pin`,
cr.currentplan AS `Current Plan`,
r.servicecredits AS `Service Crdits w/o PS/AC`,
r.multipleplans AS `Multiple Plans/Tiers?`,
r.confirmationlettermailed AS `Mailed Confirm Letter`,
r.workbooksetup AS `Set Up Excel Workbook`,
ct.calcteam AS `Calculation Team`,
co.name AS `Assigned Staff`,
r.reviewdate AS`Review Date`,
bs.statusreported AS`BoardStatusID`,
r.reciprocityid AS `Reciprocity?`,
r.employercodeid AS `Employer`,
d.departmentname AS `Department`,
r.pendingpurchase AS `Pending Purchase(s)?`,
j.joinder AS `Joinder or Pending DRO?`,
dp.agendadisability AS `DisabilityID`,
ry.reciprocalstatus,
o.orientationstatus AS `Orientation Elected?`,
r.orientationdate AS `Orientation Date`,
rp.reviewername AS `Designated Reviewer`,
r.filesetupapproved AS `File Set-Up Approved`,
r.agendaapplication AS `Agenda Application`,
r.estimatetoreviewer AS `Estimate to Reviewer`,
r.estimatetosupervisor AS `Estimate to Supervisor`,
r.estimateapproved AS `Estimate Approved`,
r.finalpaycheck AS `Final Paycheck Date`,
r.finalservice AS `Final Service with PS/AC`,
r.finaltoreviewer AS `Final Calc to Reviewer`,
r.finaltosupervisor AS `Final Calc to Supervisor`,
r.finalapproved AS `Final Calc Approved`,
r.applicationcancelled AS `App Cancelled by Member?`,
r.retelectiondistributed AS `Retirement Election Distributed`,
r.retelectionreturned AS `Retirement Election Returned`,
p.agendaoption AS `Option/Payment Selected`,
r.tempannuityid AS `Age Request for Temp Annuity`,
r.finalallowance AS `Final Allowance Calculation`,
r.continuance AS `Continuance`,
r.payrollformsstaff AS `Payroll Forms Completed (Staff)`,
r.agendapayment AS `Option-Payment`,
r.payrollformssupervisor AS `Payroll Forms Reviewed (Supv)`,
r.cboapprovedallowance AS `Allowance Approved (CBO)`,
r.allowanceestimated AS `Allowance Estimated?`,
r.allowenteredinpayroll AS `Allowance Entered In Payroll`,
r.distributioncycleid AS `Distribution Cycle for 1st Payment`,
r.firstpaydate AS `Distribution Date for 1st Payment`,
r.allowancefinalized AS `Allowance Finalized`,
r.fileimaged AS `Retirement File Imaged`
FROM ((((((((((((tblretirements r
LEFT JOIN tblcalculationpersonnel cp
ON r.coordinatorid = co.coordinatorid)
LEFT JOIN tblcurrentplan cr
ON r.currentplanid = cr.currentplanid)
LEFT JOIN tblbenefitinprocress bp
ON r.benefitinprocess = bp.retirementtypeid)
LEFT JOIN tblpaymentoption p
ON r.optionid = p.optionid)
LEFT JOIN tblreviewpersonnel rp
ON r.reviewerid = rp.reviewerid)
LEFT JOIN tblorientationstatus o
ON r.orientationid = o.orientationid)
LEFT JOIN tbldisabilitypending dp
ON r.disabilityid = dp.disabilityid)
LEFT JOIN tbljoinder j
ON r.joinderid = j.joinderid)
LEFT JOIN tbldepartment dt
ON r.departmentid = d.departmentid)
LEFT JOIN tblemployercode e
ON r.employercodeid = e.employercodeid)
LEFT JOIN tblreciprocity ry
ON r.reciprocityid = ry.reciprocityid)
LEFT JOIN tblcalculationteam ct
ON r.calculationteamid = ct.calculationteamid)
LEFT JOIN tblboardstatus bs
ON r.boardstatusid = bs.boardstatusid
WHERE clause
WHERE r.applicationcancelled = 'No'
AND r.receiptdate IS NULL
OR r.receiptdate BETWEEN (
IIF(MONTH(DATE()) < 7,
DATESERIAL(YEAR(DATE()) - 1, 7, 1),
DATESERIAL(YEAR(DATE()), 7, 1))
)
AND (
IIF(MONTH(DATE()) < 7,
DATESERIAL(YEAR(DATE()), 6, 30),
DATESERIAL(YEAR(DATE()) + 1, 6, 30))
)
IS not clear why you are using case in where but if you want use in between should be
" WHERE tblretirements.ApplicationCancelled = 'No'
AND (tblretirements.ReceiptDate IS NULL OR tblretirements.ReceiptDate BETWEEN
( CASE WHEN MONTH(getdate()) < 7 THEN DATEFROMPARTS(YEAR(getdate())-1,7,1)
ELSE DATEFROMPARTS(YEAR(getdate()),7,1)
End )
AND (
CASE
WHEN MONTH(getdate()) < 7 THEN DATEFROMPARTS(YEAR(getdate()),6,30)
ELSE DATEFROMPARTS(YEAR(getdate())+1,6,30)
End ) ) "

Syntax error on multiple join statement

Hello, I'm getting a syntax error on this sql statement, can anyone advise thanks
String sql = "Select tblStudent.*,tblSchool.*,tblAgents.* " +
"FROM tblStudent LEFT JOIN tblSchool " +
"ON (tblStudent.schoolID = tblSchool.schoolID) " +
"LEFT JOIN tblAgents " +
"ON (tblStudent.agentID = tblAgents.agentID) " +
"WHERE tblStudent.StudentID='" + studentID + "'";
I was hoping that I could do multiple joins
But I am getting a syntax error.
For access, parenthesis with multiple joins means the following. If you have three joins, there are two left parenthesis after the from. The last join does not have a right parenthesis.
String sql = "Select tblStudent.*,tblSchool.*,tblAgents.* " +
"FROM (tblStudent LEFT JOIN tblSchool " +
"ON (tblStudent.schoolID = tblSchool.schoolID)) " +
"LEFT JOIN tblAgents " +
"ON (tblStudent.agentID = tblAgents.agentID) " +
"WHERE tblStudent.StudentID='" + studentID + "'";
Access SQL injection has been covered in other threads .
String sql = "Select
tblStudent.StudentID,tblStudent.studentFirstName,"+
tblStudent.studentLastName,tblSchool.schoolName," +
tblAgents.agentFirstName,tblAgents.agentLastName " +
"FROM (tblStudent LEFT JOIN tblSchool " +
"ON (tblStudent.schoolID = tblSchool.schoolID)) " +
"LEFT JOIN tblAgents " +
"ON (tblStudent.agentID = tblAgents.agentID) " +
"WHERE tblStudent.StudentID=#studentID";
I believe your final SQL should look like this:
SELECT tblStudent.*
,tblSchool.*
,tblAgents.*
FROM tblSchool
RIGHT JOIN (
tblAgents RIGHT JOIN tblStudent ON tblAgents.agentID = tblStudent.agentID
) ON tblSchool.schoolID = tblStudent.schoolID
WHERE tblStudent.StudentID=111;
So, the VBA code for creating this SQL should be
Dim sql As String
sql = "SELECT tblStudent.* ,tblSchool.* ,tblAgents.* " & _
"FROM tblSchool RIGHT JOIN (" & _
"tblAgents RIGHT JOIN tblStudent ON tblAgents.agentID = tblStudent.agentID" & _
") ON tblSchool.schoolID = tblStudent.schoolID " & _
"WHERE tblStudent.StudentID=" & studentID
Here I assume that studentID is numeric field. Also I would recommend to do not use * for selecting the data from more than one table, otherwise column names may be unpredictable and as mentioned in comments, it will require additional resources, which won't be used.

Paradox DB SQL Multiple JOINS

I'm working on a legacy VB6 project and I need to make a JOIN call like this:
SELECT C.Cnum, C.RealDate, M.Name, R.Price, R.Qnt, R.RealPrice, R.QntP, R.QntR, M.Name
FROM "CHECK" C
LEFT JOIN "RCHECK" R ON C.Cnum = R.Cnum
LEFT JOIN "PCHECK" P ON C.Cnum = P.Cnum
LEFT JOIN "MONEY" M ON P.Curency = M.Sifr
LEFT JOIN "MENU" MN ON R.Sifr = MN.Sifr
WHERE C.Cnum > 0 ORDER BY C.Cnum
I use "Driver={Microsoft Paradox Driver (*.db )};DriverID=538" as a part of connection string but it seems it doesn't support more than one join! Which is weird.
Any ideas how to solve/workaround it?
And yes, when I run this query in Borland Database Desktop, it works fine.
Update 1:
My VB Code:
Dim Conn As New ADODB.Connection
Dim sConnStr As String
Dim sQuery As String
sConnStr = "Driver={Microsoft Paradox Driver (*.db )};DriverID=538;Fil=Paradox 5.X;CollatingSequence=ASCII;DBQ=C:\DBTOFTP\BUFF;DefaultDir=C:\DBTOFTP\BUFF;PWD=SOMEPASS;"
sQuery = "SELECT C.Cnum, C.RealDate, M.Name, R.Price, R.Qnt, R.RealPrice, R.QntP, R.QntR, M.Name " & _
"FROM ""CHECK"" C " & _
"LEFT JOIN ""RCHECK"" R ON C.Cnum = R.Cnum " & _
"LEFT JOIN ""PCHECK"" P ON C.Cnum = P.Cnum " & _
"LEFT JOIN ""MONEY"" M ON P.Curency = M.Sifr " & _
"LEFT JOIN ""MENU"" MN ON R.Sifr = MN.Sifr " & _
"WHERE C.Cnum > 0 " & _
"ORDER BY C.Cnum"
Conn.ConnectionString = sConnStr
Conn.Open
Some old drivers often requires that multiple JOINs must be enclosed in parentheses.
Try something like this:
FROM
(
"CHECK" C
INNER JOIN
"RCHECK" R
ON C.Cnum = R.Cnum
)
INNER JOIN
"PCHECK" P
ON P.Cnum = C.Cnum