我有以下查询,但是当我传递此别名列名的参考名称时,它显示无效的列名我该怎么做
select OM.*,
convert(int,Replace(Ltrim(Replace(left(OM.mstrefc,6), '0', ' ')), ' ', '0')) as partycode,
OI.*,
Ac.AcctName,
Ac.acctaddr,
UN.UnitName
from ordemst OM
join ordeitd OI
on OM.mstCode = OI.ItdCode
join Account Ac
on OM.partycode = Ac.acctcode
left join unitdet UN
on OI.ItdUnit = UN.unitcode and
OI.CompCode = UN.CompCode
where OM.MstCode = 47 and
OM.MstType =79 and
OM.CompCode =117 and
AC.compcode =117 and
OI.Compcode=117