1

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

Ali Imran
  • 646
  • 1
  • 9
  • 26
  • it should be `where PaymentAmount-PaymentPosted = 22`. There is no way to use column alias in WHERE clause. – King King Nov 13 '17 at 06:20

2 Answers2

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.

Anagha
  • 918
  • 1
  • 8
  • 17
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
Md. Suman Kabir
  • 5,243
  • 5
  • 25
  • 43