Add filter on column which subtract to columns

时间:2017-11-13 06:16:20

标签: sql sql-server stored-procedures

i have long store procedure in whcih i want Add filter on this Column

select (PaymentAmount-PaymentPosted) as Unapplied, BalancDue from ERAMaster
 where Unapplied = 22

but i run the query they give me error invalid column name. any one tell me the write way to Add filter on Unapplied Column

2 个答案:

答案 0 :(得分:1)

It should be like this:

select (PaymentAmount-PaymentPosted) as Unapplied, BalancDue from ERAMaster
 where (PaymentAmount-PaymentPosted) = 22

'Unapplied' is not a column name it is only alias.

答案 1 :(得分:1)

You can do it like below :

select * from 
(
    select (PaymentAmount-PaymentPosted) as Unapplied, BalancDue from ERAMaster
) as T where Unapplied = 22

Or like this :

select (PaymentAmount-PaymentPosted) as Unapplied, BalancDue from ERAMaster
where PaymentAmount-PaymentPosted = 22