一条sql语句,不知道怎么写啦
2007-06-08 00:11
288 查看
--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'
现在就是在每一次
相关文章推荐
- 一条sql语句,不知道怎么写啦
- navicate怎么用sql语句插入一条语句
- 一个不知道怎么去写的sql语句
- php中mysql一条sql语句查询出所有符合条件的数据,该怎么写?
- 一条sql语句 (合并结果)
- SQL 一条SQL语句 统计 各班总人数、男女各总人数 、该班级男女 比例
- SQL语句 - 随机抽取一条记录
- 一条SQL语句
- 怎么用批处理*.bat 执行文件目录下面的SQL语句脚本(批量的)。。。@echo off是什么意思?
- Java大牛养成记——一条SQL语句更新同一张表中的两条数据
- 一个有趣的SQL命题 用一条语句切换BIT型的真假值
- sql2005中运用一条sql语句完成数据导出到Excel中
- 数据库表,3个字段,姓名,薪水,部门,用一条sql语句求每个部门薪水最高的人姓名
- 一条SQL语句
- 转载:如何写个SQL语句查询一个字段里是否有重复记录如果有只读取其中一条记录
- SQL怎么随机提取出一条信息 mysql 获取随机记录
- 一条sql语句删除两条重复值的语句
- CPT文件怎么打开,CPT报表怎么查看其SQL语句
- 一条SQL语句中算日销售额和月销售额