SQL高手请进,不吝指教。谢谢(50分)

  • 主题发起人 主题发起人 mkbss
  • 开始时间 开始时间
M

mkbss

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大哥大姐,请看以下的SQL语句:

select d.corppn"生产型号",d.Rev"版本",d.layer"层数",a.workno"工单号码",a.lotno"批卡号",a.outqty"出帐数量",a.inqty"入帐数量",
报废面积=a.inscrap*cast(g.paramvalue as float)*d.Layer,
a.passovertime"过数时间",a.passoverby"入帐人员",a.outscrap"废单元",a.inscrap"报废单元",
出帐单位=(select UnitName from Mkt_Unit where UnitNo=A.OutUnit),
入帐单位=(select UnitName from Mkt_Unit where UnitNo=A.InUnit),
毛面积=cast(cast(e.paramvalue as float)*cast(f.paramvalue as float)/10000 as float),
cast(g.paramvalue as float) as 单元面积,
b.techname"出帐工序",c.TechName"入帐工序",
OutAreaTotal=cast((CASE UPPER(a.OutUnit)
WHEN 'WP' THEN
CASE WHEN d.WplAry=0 THEN a.OutQty*d.AryPcs*d.QuotArea
ELSE a.OutQty*d.WplAry*d.AryPcs*d.QuotArea END
WHEN 'PNL' THEN a.OutQty*d.AryPcs*d.QuotArea
WHEN 'PCS' THEN a.OutQty*d.QuotArea END) as numeric(14,4)),
过数面积=cast((CASE UPPER(a.OutUnit)
WHEN 'WP' THEN
CASE WHEN d.WplAry=0 and d.layer<>0 THEN a.OutQty*cast(cast(e.paramvalue as float)*cast(f.paramvalue as float)/10000 as float)*d.Layer
ELSE a.OutQty*cast(cast(e.paramvalue as float)*cast(f.paramvalue as float)/10000 as float)*d.Layer END
WHEN 'PNL' THEN a.OutQty*cast(cast(e.paramvalue as float)*cast(f.paramvalue as float)/10000 as float)*d.Layer
WHEN 'PCS' THEN a.OutQty*cast(g.paramvalue as float)*d.Layer end) as numeric(14,4))

[red]when d.layer=0 then
毛面积=cast(cast(e.paramvalue as float)*cast(f.paramvalue as float)/10000 as float) end[/red]


from pro_passoverrec a left join
pub_TechInfo c on a.InTechNo=c.TechNo left join pub_techInfo b on a.OutTechNo=b.TechNo left join mkt_PnInfo d on a.ProdNo=d.ProdNo
left join ppe_miitem e on d.prodno=e.prodno left join ppe_miitem f on e.prodno=f.prodno left join ppe_miitem g on e.prodno=g.prodno
where 1=1 and e.itemno='0008' and f.itemno='0009' and g.itemno='0012'
and a.OutTechNo In (select techno from pub_TechInfo where passover =1) and a.InTechNo In( select techno from pub_TechInfo where passover =1)
Order By PassoverTime


一加上红色的语句就出错,小弟想不通有什么语法错误。
请高手不吝指点迷津。
谢谢
 
CASE WHEN d.WplAry=0 and d.layer<>0 THEN a.OutQty*cast(cast(e.paramvalue as float)*cast(f.paramvalue as float)/10000 as float)*d.Layer
ELSE a.OutQty*cast(cast(e.paramvalue as float)*cast(f.paramvalue as float)/10000 as float)*d.Layer END
WHEN 'PNL' THEN a.OutQty*cast(cast(e.paramvalue as float)*cast(f.paramvalue as float)/10000 as float)*d.Layer
WHEN 'PCS' THEN a.OutQty*cast(g.paramvalue as float)*d.Layer end) as numeric(14,4))

when d.layer=0 then
cast(cast(e.paramvalue as float)*cast(f.paramvalue as float)/10000 as float) end
毛面积
或者
end as 毛面积
毛面积为一个字段的别名.
 
回复hwh6666:

查询分析器运行时出现错误提示:在关键字 'when' 附近有语法错误
如果没有 when d.layer=0 then
毛面积=cast(cast(e.paramvalue as float)*cast(f.paramvalue as float)/10000 as float) end
这句,运行是没有问题的,可以得出结果。现在小弟我想要加多一个条件呀
求救
 
后退
顶部