Difference between revisions of "VbzCart/queries"

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
Jump to navigation Jump to search
(qryCbx_Items - not tested; need qryCatNum_Items too.)
 
(→‎Views: qryCat_Items; need qryCat_Titles next)
Line 5: Line 5:
 
==Views==
 
==Views==
 
Some common prefixes:
 
Some common prefixes:
* '''qryCbx_''': queries used for filling comboboxes. The unique ID will always be the first field, and the text to display will always be the second field; additional fields may be provided for use in further qryCbx_ queries which show a subset of the results.
+
* '''qryCbx_''': queries used for filling comboboxes. The unique ID will always be the first field, and the text to display will always be the second field; additional fields may be provided for use in further '''qryCbx_''' queries which show a subset of the results.
* '''qryCatNum_''': queries which build catalog numbers, possibly including other information from the tables they draw on in so doing.
+
* '''qryCat_''': queries which build catalog numbers or information by joining multiple tables. (In Access, the convention was '''qryCatNum_'''.)
 +
===qryCat_Items===
 +
<sql>SELECT
 +
  i.ID,
 +
  i.ID_Title,
 +
  (t.ID IS NOT NULL) AS TitleExists,
 +
  t.ID_Supplier,
 +
  i.PriceSell,
 +
  i.PriceList,
 +
  i.PriceBuy,
 +
  i.CatNum,
 +
  t.CatNum AS Title_CatNum,
 +
  t.Name AS Title_Name,
 +
  i.ID_ItTyp,
 +
  i.ID_ItOpt,
 +
  i.ItOpt_Descr,
 +
  i.ItOpt_Sort,
 +
  CONCAT(t.Name, IF(i.ItOpt_Descr IS NULL,'',CONCAT(' (',i.ItOpt_Descr,')')) AS Descr,
 +
  i.Supp_CatNum,
 +
  i.isForSale,
 +
  i.isPulled,
 +
  i.QtyMin_Stk,
 +
  t.RstkMin AS QtyMin_Rstk_Title
 +
FROM cat_items AS i LEFT JOIN qryCat_Titles AS t on i.ID_Title=t.ID
 +
ORDER BY t.ID IS NOT NULL, i.CatNum, i.ItOpt_Sort;</sql>
 
===qryCbx_Items===
 
===qryCbx_Items===
 
<sql>SELECT
 
<sql>SELECT
Line 18: Line 42:
 
       AS Descr,
 
       AS Descr,
 
   i.isForSale
 
   i.isForSale
FROM qryCatNum_Items AS i
+
FROM qryCat_Items AS i
 
ORDER BY NOT i.isPulled, i.isForSale, i.CatNum;</sql>
 
ORDER BY NOT i.isPulled, i.isForSale, i.CatNum;</sql>

Revision as of 11:34, 3 October 2007

Navigation

VbzCart: data views

Overview

"Views" in MySQL are like SELECT "queries" in MS Access, i.e. they pull data from existing tables and are themselves usable as data sources in much the same way that tables are (and in which result sets from functions are not).

Views

Some common prefixes:

  • qryCbx_: queries used for filling comboboxes. The unique ID will always be the first field, and the text to display will always be the second field; additional fields may be provided for use in further qryCbx_ queries which show a subset of the results.
  • qryCat_: queries which build catalog numbers or information by joining multiple tables. (In Access, the convention was qryCatNum_.)

qryCat_Items

<sql>SELECT

 i.ID,
 i.ID_Title,
 (t.ID IS NOT NULL) AS TitleExists,
 t.ID_Supplier,
 i.PriceSell,
 i.PriceList,
 i.PriceBuy,
 i.CatNum,
 t.CatNum AS Title_CatNum,
 t.Name AS Title_Name,
 i.ID_ItTyp,
 i.ID_ItOpt,
 i.ItOpt_Descr,
 i.ItOpt_Sort,
 CONCAT(t.Name, IF(i.ItOpt_Descr IS NULL,,CONCAT(' (',i.ItOpt_Descr,')')) AS Descr,
 i.Supp_CatNum,
 i.isForSale,
 i.isPulled,
 i.QtyMin_Stk,
 t.RstkMin AS QtyMin_Rstk_Title

FROM cat_items AS i LEFT JOIN qryCat_Titles AS t on i.ID_Title=t.ID ORDER BY t.ID IS NOT NULL, i.CatNum, i.ItOpt_Sort;</sql>

qryCbx_Items

<sql>SELECT

 i.ID,
 CONCAT(
   IF(i.isPulled,CONCAT('!PULLED (',i.ID,')'),),
   i.CatNum,
   IF(i.Supp_CatNum IS NULL,,CONCAT('[',i.SuppCatNum,']')),
   IF(i.isForSale,,' n/a'),
   i.Descr)
     AS Descr,
 i.isForSale

FROM qryCat_Items AS i ORDER BY NOT i.isPulled, i.isForSale, i.CatNum;</sql>