獨角戲
三個視圖數據結構﹕
[red]v_sale_item a:[/red]
CREATE VIEW [DBO].V_SALE_ITEM AS
SELECT Salegen.Loc_id AS Sl_loc_id,
Salegen.inv_date AS Sl_inv_date,
Salegen.inv_time AS Sl_inv_time,
Salegen.inv_no AS Sl_inv_no,
Salegen.sal_id AS Sl_sal_id,
Salegen.invamt AS Sl_invamt,
Salegen.otrchg AS Sl_otrchg,
Salegen.invdisc AS Sl_invdisc,
Salegen.Remark AS Sl_remark,
Salegen.Sex As Sl_Sex,
Salegen.Age As Sl_Age,
V_Saledet.Sl_itmseq,
V_Saledet.Sl_colszseq,
V_Saledet.Sl_log_id,
V_Saledet.Sl_salseq,
V_Saledet.Sl_salqty,
V_Saledet.Sl_currpri,
V_Saledet.Sl_itmdisc,
V_Saledet.Sl_itmamt,
V_Saledet.Sl_totcost4,
Sl_item,
Sl_bnd_id,
SL_dep_id,
Sl_style,
Sl_div_id,
Sl_yea_id,
Sl_sea_id,
Sl_sea_id2,
Sl_origpri
FROM Salegen,V_Saledet
WHERE Salegen.Loc_id = V_Saledet.Sl_Loc_id AND
Salegen.inv_date = V_Saledet.Sl_inv_date AND
Salegen.inv_no = V_Saledet.Sl_inv_no
v_location:
CREATE VIEW [DBO].V_LOCATION AS
SELECT LOCATION.CMP_ID AS lc_cmp_id,
SUBSTRING(LTRIM(COMPANY.NAME30),1,10) AS lc_cmpname,
LOCATION.CTR_ID AS lc_ctr_id,
MGTCTR.CTRSEQ AS lc_ctrseq,
MGTCTR.NAME10 AS lc_portname,
LOCATION.LGP_ID AS LC_lgp_id,
LOCGRP.NAME10 AS lc_cityname,
LOCATION.LOC_ID AS lc_loc_id,
SUBSTRING(LTRIM(locatdet.NAME20),1,10) AS lc_shopname,
LOCATION.LTY_ID AS lc_lty_id,
LOCTYPE.NAME10 AS lc_typename,
LOCATION.SELLAREA AS lc_sellarea,
LOCATION.ACT_IND AS lc_active,
CONVERT(CHAR(10),LOCATDET.opendate,103) AS lc_opendate
FROM locatdet,LOCATION,LOCGRP,MGTCTR,LOCTYPE,COMPANY
WHERE LOCATION.CTR_ID = MGTCTR.CTR_ID AND
LOCATION.CMP_ID = MGTCTR.CMP_ID AND
LOCATION.CTR_ID = LOCGRP.CTR_ID AND
LOCATION.CMP_ID = LOCGRP.CMP_ID AND
LOCATION.LGP_ID = LOCGRP.LGP_ID AND
LOCATION.LTY_ID = LOCTYPE.LTY_ID AND
LOCATION.CMP_ID = COMPANY.CMP_ID AND
locatdet.loc_id = location.loc_id
v_itmast_sle b :
Create view dbo.v_itmast_sle As
select itmseq, bnd_id, div_id, yea_id, sea_id, dep_id,
case when left(cat_id,1)='B' OR left(cat_id,1)='C' then 'B'
else 'A' end sle_id,cat_id, was_id, fab_id, sea_id2, sty_id, name30, origpri,
RIGHT(CONVERT(char(4), yea_id), 1) + CONVERT(char(1), sea_id) + '-' + CONVERT(char(4), sty_id) As it_itemID,ic_id
from itmast where
dep_id in ('3','7')
and sea_id2=1
union all
select itmseq, bnd_id, div_id, yea_id, sea_id, dep_id,
case when (left(cat_id,1)='A' OR left(cat_id,1)='D') then 'A'
else 'B' end sle_id,cat_id, was_id, fab_id, sea_id2, sty_id, name30, origpri,
RIGHT(CONVERT(char(4), yea_id), 1) + CONVERT(char(1), sea_id) + '-' + CONVERT(char(4), sty_id) As it_itemID,ic_id
from itmast where
dep_id in ('3','7')
and sea_id2=2
union all
select itmseq, bnd_id, div_id, yea_id, sea_id, dep_id,
'Z' As sle_id,cat_id, was_id, fab_id, sea_id2, sty_id, name30, origpri,
RIGHT(CONVERT(char(4), yea_id), 1) + CONVERT(char(1), sea_id) + '-' + CONVERT(char(4), sty_id) As it_itemID,ic_id
from itmast where
(dep_id in ('3','7') and sea_id2 not in (1,2))
or (dep_id not in ('3','7'))