How to Create CPHSTTRX_VIEW with Left Join to CPINVHDR Due to Invoice Database Archive

How to Create CPHSTTRX_VIEW with Left Join to CPINVHDR Due to Invoice Database Archive

Release Date: 12/6/2019
Version: All

QI had to run Archive Invoices in the old fashioned way as the company ran out of invoice numbers and I didn’t have time to go to 8.5 (modifications). I ran the Archive procedure as outlined in the KB article below with an additional step that kept all of the 2019 invoices in the production data folder. 

Everything is working well on the operation side.

There is an issue with about 10 Crystal reports that compare 2018 and 2019 sales numbers. After I was notified about these reports, I planned to add the CPHSTTRX from the database of the Data_50 (the archive folder) with a Left Outer Join so that both 2018 and 2019 data can be accessed. Unfortunately, the CPHSTTRX_VIEW was used on the original report, which makes things extremely difficult.

My Question: Can you suggest how we can change the CPHSTTRX_VIEW to be Left Outer Join (as in all CPHSTTRX and any CPINVHDR if they exist)? If it is too difficult, the 10 reports will have to be rewritten…

A - Here is the original SQL script to create the view CPHSTTRX_VIEW: 

Create View CPHSTTRX_VIEW As
Select CPHSTTRX.*, ARCUSFIL.*, CPINVHDR.*, IMITMFIL.*
FROM CPHSTTRX, ARCUSFIL, CPINVHDR, IMITMFIL
WHERE HIST_TRX_CUST_NO = CUS_NO
AND HIST_TRX_INV_NO = INV_NO
AND HIST_TRX_ITEM_NO = ITEM_NO;
  


You could create a new left join view CPHSTTRX_VIEWL by using the following:

Create View CPHSTTRX_VIEWL As
Select CPHSTTRX.*, ARCUSFIL.*, CPINVHDR.*, IMITMFIL.*
FROM CPHSTTRX INNER JOIN ARCUSFIL
ON HIST_TRX_CUST_NO = CUS_NO
LEFT JOIN CPINVHDR
ON HIST_TRX_INV_NO = INV_NO
INNER JOIN IMITMFIL
ON HIST_TRX_ITEM_NO = ITEM_NO;  

If you want to use the same view name (easier with your Crystal Report,) then you need to drop the existing view first before creating the view again:

Drop View CPHSTTRX_VIEW;

Create View CPHSTTRX_VIEW As
Select CPHSTTRX.*, ARCUSFIL.*, CPINVHDR.*, IMITMFIL.*
FROM CPHSTTRX INNER JOIN ARCUSFIL
ON HIST_TRX_CUST_NO = CUS_NO
LEFT JOIN CPINVHDR
ON HIST_TRX_INV_NO = INV_NO
INNER JOIN IMITMFIL
ON HIST_TRX_ITEM_NO = ITEM_NO;  

In either case, you need to save this script so that in the future, when the DDF is updated, you can re-apply this script.

EMK


    • Related Articles

    • I Am Running Out of Invoice Numbers -- I Need Direction to Archive Invoices

      Q: Within the next 6 months we will run out of invoice numbers. I don't want to purge my invoice history because it contains valuable data that I would like to go back to in the future. So I would prefer a method to archive my invoice history instead ...
    • Feature - Invoice History Archive

      Release Date: 8/23/21 Version: 8.6 and Above The current invoice history data tables CPINVHDR, CPINVLIN, CPINVOPT, CPINVMTL, CPINVRTG, CPBOXFHS (history version of CPBOXFIL), CPBOXHSR (history version of CPBOXSER), CPBOXHST (history version of ...
    • An Example of Debugging NOTE_ORD_VIEW PSQL Expression Evaluation Error

      Q - When I try to access the NOTE_ORD_VIEW in the PSQL control center, I get this error: "[LNA][Pervasive][ODBC Engine Interface]Expression evaluation error." See sample screen below. It does not display any results, but it does display the create ...
    • Cannot Create DDFs Due to Metadata Version Mismatch

      Release Date: 11/28/2022 Version: 8.5 or Higher Q - We recently upgraded to Actian PSQL 15. I wanted to create a new ODBC database. So I go to PSQL Control Center, right click on the "Database" node and choose "New" to create the database, but it is ...
    • How to Improve Query Performance When Retrieving Data from Notes & Invoice History

      Release Date: 12/12/17 Q - I am trying to get all SHIP notes with related invoice information for a specific customer for a specific day. The speed of my attempts has been okay, but it feels like it could perform much faster. How can the below be ...