--SELECT * FROM BS_GoodsInfo 商品信息
--GO
--SELECT * FROM BS_Customer 客户信息
--GO
--SELECT * FROM BS_DisSaleSystem 特价促销价格体系
--GO
--SELECT * FROM BS_DisPriceType 特价促销价格体系类别
--GO
--SELECT * FROM BS_DisSaleGoods 特价促销价格体系商品
--GO
--select * from BS_ConPriceSystem 客户合同价格体系表
--go
--select * from BS_ConPriceType
--go
--select * from BS_ConPriceGoods 客户合同价格体系商品
--go
DECLARE @iSDisPrice as int --这个是为了判断是不是有促销价格
DECLARE @iSConPrice as int --这个是为了判断是不是有合同价格
declare @DisPriceDate as int --这个是为了标志是不是在这个时间范围里.
declare @BeforePrice as int --这个是为了判断是不是上一次价格
--这里判断是不是有促销价格
SET @iSDisPrice = (SELECT COUNT(*) FROM BS_DisSaleSystem where CustID = '8566363' AND CompanyID = '0111102')
if @iSDisPrice > 0
begin
--这里判断在这个时间里是不是有促销价格
set @DisPriceDate = (select count(*) from BS_DisPriceType where TypeCode in (SELECT TypeCode FROM BS_DisSaleSystem where CustID = '8566363' AND CompanyID = '002') and CompanyID = '002' and frmdate <= getdate() and getdate()<= ToDate )
if @DisPriceDate > 0
begin
--SELECT * FROM BS_DisSaleGoods where CompanyID = '002' and TypeCode in (select TypeCode from BS_DisPriceType where TypeCode in (SELECT TypeCode FROM BS_DisSaleSystem where CustID = '8566363' AND CompanyID = '002') and CompanyID = '002' and frmdate <= getdate() and getdate()<= ToDate )
SELECT isnull(a.conPrice,0) as Price, * from View_dSaleBill INNER JOIN (SELECT * FROM BS_DisSaleGoods where CompanyID = '002' and TypeCode in (select TypeCode from BS_DisPriceType where TypeCode in (SELECT TypeCode FROM BS_DisSaleSystem where CustID = '8566363' AND CompanyID = '002') and CompanyID = '002' and frmdate <= getdate() and getdate()<= ToDate )) A ON A.CompanyID = View_dSaleBill.CompanyID and a.GoodsID = View_dSaleBill.GoodsID and View_dSaleBill.companyId = '002'
-- goto dis_goto
end
end
else
begin
--这里判断是不是有合同价格
SET @iSConPrice = (SELECT COUNT(*) FROM BS_ConPriceSystem where CustID = '8566363' AND CompanyID = '002')
if @iSConPrice > 0
begin
/* 1. 不知道怎么在这里排出促销价格的商品 */
--这里是取出它的合同价格出来,
--select * from BS_ConPriceType where TypeCode in (SELECT TypeCode FROM BS_ConPriceSystem where CustID = '8566363' AND CompanyID = '002') and CompanyID = '002'
select isnull(b.conPrice,0) as Price,* from View_dSaleBill INNER JOIN (SELECT * FROM BS_ConPriceGoods where typeCode in (select typeCode from BS_ConPriceSystem where companyID = '002' and custId = '8566363') and companyID = '002') as b on b.CompanyId = View_dSaleBill.CompanyId and b.goodsId = View_dSaleBill.goodsId where b.companyId = '002'
--print @iSConPrice
end
else
begin
/* 2. 不知道怎么在这里排出促销价格及的合同价格商品 */
--这里取出自定议上次价格
set @BeforePrice = (select count(sBillNo) as sBillNo from bs_SaleBill where CustID = '8566363' and companyID = '002')
if @BeforePrice > 0
begin
select c.NoTaxPrice as Price,* from View_dSaleBill inner join (SELECT NoTaxPrice,GoodsID,CompanyId FROM bs_dSaleBill where companyId = '002' and sBillNo = (select max(sBillNo) as sBillNo from bs_SaleBill where CustID = '8566363' and companyID = '002') and GoodsID = '002' ) as c on c.CompanyId = View_dSaleBill.CompanyId and c.GoodsId = View_dSaleBill.GoodsId and View_dSaleBill.CompanyId = '002'
end
else
/*3. 不知道怎么在这里排出促销价格,合同价格商品,上次输入价格 */
--这里的价格为0
begin
select '0' as Price,* from View_dSaleBill inner join (SELECT NoTaxPrice,GoodsID,CompanyId FROM bs_dSaleBill where companyId = '002' and sBillNo = (select max(sBillNo) as sBillNo from bs_SaleBill where CustID = '8566363' and companyID = '002') and GoodsID = '002' ) as c on c.CompanyId = View_dSaleBill.CompanyId and c.GoodsId = View_dSaleBill.GoodsId and View_dSaleBill.CompanyId = '002'
end
end
end
--dis_goto: SELECT isnull(a.conPrice,0) as Price, * from View_dSaleBill INNER JOIN (SELECT * FROM BS_DisSaleGoods where CompanyID = '002' and TypeCode in (select TypeCode from BS_DisPriceType where TypeCode in (SELECT TypeCode FROM BS_DisSaleSystem where CustID = '8566363' AND CompanyID = '002') and CompanyID = '002' and frmdate <= getdate() and getdate()<= ToDate )) A ON A.CompanyID = View_dSaleBill.CompanyID and a.GoodsID = View_dSaleBill.GoodsID
--select isnull(b.conPrice,0), * from View_dSaleBill INNER JOIN (SELECT * FROM BS_ConPriceGoods where typeCode in (select typeCode from BS_ConPriceSystem where companyID = '002' and custId = '8566363') and companyID = '002') as b on b.CompanyId = View_dSaleBill.CompanyId and b.goodsId = View_dSaleBill.goodsId where b.companyId = '002'
--取出自定议上次价格
--select c.NoTaxPrice as Price,* from View_dSaleBill inner join (SELECT NoTaxPrice,GoodsID,CompanyId FROM bs_dSaleBill where companyId = '002' and sBillNo = (select max(sBillNo) as sBillNo from bs_SaleBill where CustID = '8566363' and companyID = '002') and GoodsID = '002' ) as c on c.CompanyId = View_dSaleBill.CompanyId and c.GoodsId = View_dSaleBill.GoodsId and View_dSaleBill.CompanyId = '002'
现在就是在每一次