0

I am trying to run a query where i can use an alias in where clause

For example:

Select V.Fees - Coalesce(V.Payment,0) - Coalesce (V.Adjustment,0) AS Balance
[
the inner join query for the tables
]
Where A.Order not Null and Balance = 0
Order by Name

but as usual it is not able to recognize Balance under where?

How can we fix this?

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786

2 Answers2

0

The only way to do what you're asking is to put that field in a CTE and reference it through a join of the CTE.

Mr. Mascaro
  • 2,693
  • 1
  • 11
  • 18
0

you can repeat the expression in the where clause

Select V.Fees - Coalesce(V.Payment,0) - Coalesce (V.Adjustment,0) AS Balance
[
the inner join query for the tables
]
Where A.Order not Null and (V.Fees - Coalesce(V.Payment,0) - Coalesce (V.Adjustment,0)) = 0
Order by Name
radar
  • 13,270
  • 2
  • 25
  • 33