--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@iSDisPriceasint--这个是为了判断是不是有促销价格 DECLARE@iSConPriceasint--这个是为了判断是不是有合同价格 declare@DisPriceDateasint--这个是为了标志是不是在这个时间范围里. declare@BeforePriceasint--这个是为了判断是不是上一次价格 --这里判断是不是有促销价格 SET@iSDisPrice= (SELECTCOUNT(*) FROM BS_DisSaleSystem where CustID ='8566363'AND CompanyID ='0111102') if@iSDisPrice>0 begin --这里判断在这个时间里是不是有促销价格 set@DisPriceDate= (selectcount(*) from BS_DisPriceType where TypeCode in (SELECT TypeCode FROM BS_DisSaleSystem where CustID ='8566363'AND CompanyID ='002') and CompanyID ='002'and frmdate <=getdate() andgetdate()<= 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 ) SELECTisnull(a.conPrice,0) as Price, *from View_dSaleBill INNERJOIN (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() andgetdate()<= 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= (SELECTCOUNT(*) 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' selectisnull(b.conPrice,0) as Price,*from View_dSaleBill INNERJOIN (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= (selectcount(sBillNo) as sBillNo from bs_SaleBill where CustID ='8566363'and companyID ='002') if@BeforePrice>0 begin select c.NoTaxPrice as Price,*from View_dSaleBill innerjoin (SELECT NoTaxPrice,GoodsID,CompanyId FROM bs_dSaleBill where companyId ='002'and sBillNo = (selectmax(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 innerjoin (SELECT NoTaxPrice,GoodsID,CompanyId FROM bs_dSaleBill where companyId ='002'and sBillNo = (selectmax(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'