简体   繁体   中英

How to Cast a calculated field multiplied with a money field?

I have tried every CAST I can think of, and the line that will not return a value is the 'Percent' value times the P.pyd_amount which is a Money field.

SELECT O.ord_hdrnumber, O.ord_totalweight, L.lgh_tot_weight, P.pyd_amount,  
CAST(O.ord_totalweight/L.lgh_tot_weight as decimal (10,2)) AS 'Percent', 
'Percent' * P.pyd_amount  as 'Breakdown' FROM Legheader L 
LEFT OUTER JOIN paydetail P ON (L.lgh_number = P.lgh_number) 
LEFT OUTER JOIN orderheader O ON (O.mov_number = L.mov_number) 
WHERE L.lgh_number = '2659'

Percent is a alias column name which is not allowed the way you used in calculation , you have to use that expression directly for calculation

select O.ord_hdrnumber, O.ord_totalweight, L.lgh_tot_weight, P.pyd_amount,  
Cast (O.ord_totalweight/L.lgh_tot_weight as decimal (10,2)) as 'Percent', 
Cast (O.ord_totalweight/L.lgh_tot_weight as decimal (10,2)) * P.pyd_amount  as 'Breakdown' from Legheader L 
Left outer join paydetail P on (L.lgh_number = P.lgh_number) 
left outer join orderheader O on (O.mov_number = L.mov_number) 
where L.lgh_number = '2659'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM