首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

一个SQL语句的有关问题

2012-06-15 
一个SQL语句的问题,在线等selectt1.Fbillno 单据号,t1.fdate 制单时间,杨帆 制单人,2.99 部门,02.06.

一个SQL语句的问题,在线等
select 
t1.Fbillno 单据号,
t1.fdate 制单时间,
'杨帆' 制单人,
'2.99' 部门,
'02.06.02' 业务员,
kehu.f_108 仓库助记码,
'转库' 收发类别,
@thbzhi@ 退货标志,
sp.disfnumber 厂商编码,
sp.fname 存货名称,
t2.fqty 数量,
(case when T2.fentryselfb0157 is not null then T2.fentryselfb0157 else t2.fentryselfd0146 end) 建议零售价
from 
(SELECT * from icstockbill where fdate between ******** and ######## and ftrantype in(21,41) and fsupplyid is not null and (case when @thbzhi@ = 0 then t1.Fheadselfd0138=40183 AND t1.frob=1 else t1.Fheadselfd0138=40184 and t1.frob=2 end)) t1
--根据退货标志的不同,取icstockbill中的相应的数据
left outer join icstockbillentry t2 
on t1.finterid=t2.finterid 
left outer join t_organization kehu 
on t1.fsupplyid=kehu.fitemid 
left outer join Lch_icitem sp 
on t2.fitemid = sp.fitemid
where kehu.fnumber between *CustNo* and #CustNo#

--********,########,*CustNo*,#CustNo#,@thbzhi@均为参数
标红色的语句可能有问题,但不知如何更改

[解决办法]
改成如下

SQL code
where (@thbzhi@ = 0 and t1.Fheadselfd0138=40183 AND t1.frob=1) or (t1.Fheadselfd0138=40184 and t1.frob=2)
[解决办法]
SQL code
select  t1.Fbillno 单据号,t1.fdate 制单时间,'杨帆' 制单人,'2.99' 部门,'02.06.02' 业务员,kehu.f_108 仓库助记码,'转库' 收发类别,@thbzhi@ 退货标志,sp.disfnumber 厂商编码,sp.fname 存货名称,t2.fqty 数量,(case when T2.fentryselfb0157 is not null then T2.fentryselfb0157 else t2.fentryselfd0146 end) 建议零售价from  (SELECT * from icstockbill where fdate between ******** and ######## and ftrantype in(21,41) and fsupplyid is not null and ((@thbzhi@ = 0 and t1.Fheadselfd0138=40183 AND t1.frob=1) or (t1.Fheadselfd0138=40184 and t1.frob=2))) t1--根据退货标志的不同,取icstockbill中的相应的数据left outer join icstockbillentry t2  on t1.finterid=t2.finterid  left outer join t_organization kehu  on t1.fsupplyid=kehu.fitemid  left outer join Lch_icitem sp  on t2.fitemid = sp.fitemidwhere kehu.fnumber between *CustNo* and #CustNo# 

热点排行