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,198,228
  • 53
  • 572
  • 709

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,663
  • 1
  • 10
  • 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,100
  • 2
  • 23
  • 32