VbzCart/docs/procs/Upd TitleIttyps fr CatItems Titles: Difference between revisions

From Woozle Writes Code
< VbzCart‎ | docs‎ | procs
Jump to navigation Jump to search
imported>Woozle
(created in db)
imported>Woozle
(2 new fields)
Line 10: Line 10:
*** Added DROP PROCEDURE for easier maintenance.
*** Added DROP PROCEDURE for easier maintenance.
*** Actually created in database (procs did not get ported from L48 to Rizzo).
*** Actually created in database (procs did not get ported from L48 to Rizzo).
** '''2010-11-13''' Source field '''qtyInStock''' was renamed to '''qtyIn_Stk''' some time ago...
*** Added '''cntInPrint''', '''cntLines'''
* '''Notes''':
* '''Notes''':
** This is a revised version which combines two earlier procedures.
** This is a revised version which combines two earlier procedures.
Line 21: Line 23:
       ID_Dept,
       ID_Dept,
       TitleName,
       TitleName,
      cntLines,
      cntInPrint,
       cntForSale,
       cntForSale,
       cntInPrint,
       cntCurrent,
      cntInStock,
       qtyInStock,
       qtyInStock,
       currMinPrice,
       currMinPrice,
Line 32: Line 35:
       t.ID_Dept,
       t.ID_Dept,
       t.Name AS TitleName,
       t.Name AS TitleName,
      i.cntLines,
      i.cntInPrint,
       i.cntForSale,
       i.cntForSale,
       i.cntInPrint,
       i.cntCurrent,
       i.cntInStock,
       i.cntInStock,
       i.qtyInStock,
       i.qtyInStock,
Line 41: Line 46:
       SELECT
       SELECT
         ID_Title, ID_ItTyp,
         ID_Title, ID_ItTyp,
        COUNT(ID) AS cntLines,
        SUM(IF(isInPrint,1,0)) AS cntInPrint,
         SUM(IF(isForSale,1,0)) AS cntForSale,
         SUM(IF(isForSale,1,0)) AS cntForSale,
         SUM(IF(isInPrint,1,0)) AS cntInPrint,
         SUM(IF(isCurrent,1,0)) AS cntCurrent,
         SUM(IF(qtyInStock>0,1,0)) AS cntInStock,
         SUM(IF(qtyIn_Stk>0,1,0)) AS cntInStock,
         SUM(qtyInStock) AS qtyInStock,
         SUM(qtyIn_Stk) AS qtyInStock,
         MIN(PriceSell) AS currMinPrice,
         MIN(PriceSell) AS currMinPrice,
         MAX(PriceSell) AS currMaxPrice
         MAX(PriceSell) AS currMaxPrice

Revision as of 23:56, 13 November 2010

About

  • Purpose: fills Template:Vbzcart.
  • Input: Template:Vbzcart, Template:Vbzcart
  • Output: Template:Vbzcart (replace)
  • History:
    • 2007-09-20
      • Removed "WHERE i.isForSale" because this prevented the availability of discontinued items from being properly zeroed out
      • Added cntInStock calculation; see table schema
    • 2010-11-10
      • Added DROP PROCEDURE for easier maintenance.
      • Actually created in database (procs did not get ported from L48 to Rizzo).
    • 2010-11-13 Source field qtyInStock was renamed to qtyIn_Stk some time ago...
      • Added cntInPrint, cntLines
  • Notes:
    • This is a revised version which combines two earlier procedures.
    • I had a note that "the ID_Dept field is informational, not a grouping", but I don't remember what that meant and it doesn't make sense.

SQL

<section begin=sql /><mysql>DROP PROCEDURE IF EXISTS Upd_TitleIttyps_fr_CatItems_Titles; CREATE PROCEDURE Upd_TitleIttyps_fr_CatItems_Titles()

   REPLACE INTO _title_ittyps(
     ID_Title,
     ID_ItTyp,
     ID_Dept,
     TitleName,
     cntLines,
     cntInPrint,
     cntForSale,
     cntCurrent,
     qtyInStock,
     currMinPrice,
     currMaxPrice)
   SELECT
     i.ID_Title,
     i.ID_ItTyp,
     t.ID_Dept,
     t.Name AS TitleName,
     i.cntLines,
     i.cntInPrint,
     i.cntForSale,
     i.cntCurrent,
     i.cntInStock,
     i.qtyInStock,
     i.currMinPrice,
     i.currMaxPrice
    FROM (
      SELECT
        ID_Title, ID_ItTyp,
        COUNT(ID) AS cntLines,
        SUM(IF(isInPrint,1,0)) AS cntInPrint,
        SUM(IF(isForSale,1,0)) AS cntForSale,
        SUM(IF(isCurrent,1,0)) AS cntCurrent,
        SUM(IF(qtyIn_Stk>0,1,0)) AS cntInStock,
        SUM(qtyIn_Stk) AS qtyInStock,
        MIN(PriceSell) AS currMinPrice,
        MAX(PriceSell) AS currMaxPrice
      FROM cat_items AS i
      GROUP BY ID_Title, ID_ItTyp
    ) AS i LEFT JOIN cat_titles AS t ON i.ID_Title=t.ID;</mysql>

<section end=sql />