--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