﻿IF EXISTS (SELECT * FROM sysobjects WHERE name='V_INVINFO_OUTSTOCK')  --单引号里面为视图名称
    DROP VIEW V_INVINFO_OUTSTOCK --视图名称
GO
CREATE VIEW V_INVINFO_OUTSTOCK
AS
SELECT
	A.FBILLNO as BILLNO,
	A.FID as ID,
	A.FSTOCKORGID as STOCKORGID,
	A.FDOCUMENTSTATUS as DOCUMENTSTATUS,
	A.FCUSTOMERID as CUSTID,
	AF.FBILLALLAMOUNT AS BILLALLAMOUNT,
	AF.FBILLAMOUNT AS BILLAMOUNT,
	AF.FBILLTAXAMOUNT as BILLTAXAMOUNT
	,AF.FINVOICENUMBER AS INVOICENUMBER
--	,B_L.FDEPTID as APPLYID
--	,B_L.FNAME as APPLYNAME
	,1 as APPLYID
	,'' as APPLYNAME
	,C_L.FNAME as CUSTNAME
	,c.FTAXREGISTERCODE as TAXREGISTERCODE
	,c.FSOCIALCRECODE as SOCIALCRECODE
	,c_f.FINVOICETITLE as INVOICETITLE
	,c_f.FINVOICEBANKNAME as INVOICEBANKNAME
	,c_f.FINVOICEBANKACCOUNT as INVOICEBANKACCOUNT
	,c_f.FINVOICETEL as INVOICETEL
	,c.FINVOICEADDRESS as INVOICEADDRESS
FROM
	T_SAL_OUTSTOCK A
	LEFT JOIN T_SAL_OUTSTOCKFIN AF ON A.FID = AF.FID
--	left join T_BD_DEPARTMENT_L B_L on A.F_QNV_Base1 = B_L.FDEPTID and b_l.FLOCALEID = 2052
	left join T_BD_CUSTOMER C ON a.FCUSTOMERID = c.FCUSTID
	left join T_BD_CUSTOMER_L C_L ON a.FCUSTOMERID = c_l.FCUSTID and C_L.FLOCALEID = 2052
	left join T_BD_CUSTOMER_F C_F on a.FCUSTOMERID  = C_F.FCUSTID
	
