繁体   English   中英

使用 SQL Server 的列名无效

[英]Invalid column name using SQL Server

我想减去从POSquantityiPay88quantity的值,但出现错误

列名无效

我的代码:

select distinct
    tblCurrTrxIPAY88.strAmount as IPay88,
    tblCurrTrxIPAY88.strPOSOnlineRefNo,
    count(tblCurrTrxIPAY88.strPOSOnlineRefNo) as iPay88quantity,
    b.strCostCentreID,
    b.strPOSOnlineRefNo, 
    count(b.strPOSOnlineRefNo) as POSquantity,
    strPayTypeCode, b.strRemarks as Agency,
    tblMachine.strDesc As KioskName, 
    SUM(b.dblPaidAmt) as POS24,
    SUM(b.dblPaidAmt) - tblCurrTrxIPAY88.strAmount as RMVarince,
    POSquantity - iPay88quantity as Varince
from 
    tblCurrTrxMaster as b
inner join
    tblMachine on b.strMachID = tblMachine.strMachID 
inner join
    tblCurrTrxIPAY88 on b.strPOSOnlineRefNo = tblCurrTrxIPAY88.strPOSOnlineRefNo
where
    strPaymentMethod = '02' 
    and b.dtmCreated >= '1/23/2020' 
    and b.strTransStatus = '01'
group by 
    b.strCostCentreID , b.strPOSOnlineRefNo, b.strPayTypeCode, b.strRemarks, 
    tblMachine.strDesc, tblCurrTrxIPAY88.strAmount, 
    tblCurrTrxIPAY88.strPOSOnlineRefNo

iPay88Quantity 不是表中的列名,它是一个计算字段 - 您需要对基础字段进行数学运算,而不是计算字段,即:

POSquantity - count(tblCurrTrxIPAY88.strPOSOnlineRefNo) as Variance 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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