sql >> Base de Datos >  >> RDS >> Sqlserver

Cómo usar el campo calculado en otro campo de la misma consulta

Hazlo así:

;WITH YourCTE AS
(
Select
    Case ...
        When ... then ...
        When ... then ...
        When ... then ...
    End                     as FieldA
From TblSource
)
SELECT FieldA, FieldA + 1 AS FieldB, FieldA + 2 AS FieldC ....
FROM YourCTE