子查询、Concat 字符拼接 ,Cast截取小数位 函数使用

发布时间 2023-12-01 09:53:46作者: lixia64
select qh.CaseId 
,(select sh.CaseId from ServiceQuot.dbo.Header sh where qh.QutoNo = sh.HeaderNo) 
,qh.ApplierDate 
,qh.BU 
,qh.Site 
, qh.HeaderNo 
, qh.Currency 
(select sh.Customer from ServiceQuot.dbo.Header sh where qh.QutoNo = sh.HeaderNo)
, qh.PN 
,qh.QutoNo 
,(select sum(ql.Num) from QAPriceContrast.dbo.Line ql where ql.CaseId = qh.CaseId) 
,( select ( select sdl.SPMCost from ServiceQuot.dbo.Line sdl where qh.QutoLineId = sdl.LineId and shf.CaseId = sdl.CaseId) SpmCost from ServiceQuot.dbo.Header shf where qh.QutoNo = shf.HeaderNo ) 
,qh.CalQutoHumanCost 
,qh.CalQuotMaterilCost    
,qh.CalQuotOtherPrice 
,qh.CalQutoCostCount
,qh.CalActualHumanCost    
,qh.CalActualMaterialCost 
,qh.ActualOtherPrice 
,qh.CalActualCostCount
,qh.CalQutoHumanCost - qh.CalActualHumanCost    
,qh.CalQuotMaterilCost - qh.CalActualMaterialCost     
,qh.CalQuotOtherPrice -  qh.ActualOtherPrice  
,(qh.CalQutoHumanCost - qh.CalActualHumanCost) + (qh.CalQuotMaterilCost - qh.CalActualMaterialCost) + (qh.CalQuotOtherPrice -  qh.ActualOtherPrice)    
, CONCAT( cast (((qh.CalQutoCostCount - qh.CalActualCostCount) / qh.CalActualCostCount) * 100 as numeric(10, 2)),'%') 

from QAPriceContrast.dbo.Header qh where qh.CalActualCostCount is not null