- First-off: you need to address the divide-by-zero error that's looming in your query...
- Change (a.sale - a.buy) / a.saleto( a.sale - a.buy ) / NULLIF( a.sale, 0.0 )- that way you'll get aNULLinprofit_prsinstead of your query aborting entirely.
 
- ISO/ANSI SQL does not allow a SELECTprojection to refer to new column expressions in the same query "level" (i.e. within the sameSELECTclause of the same derived-table or CTE or other table expression).
- Some RDBMS extend SQL to allow it, such as MySQL.
 
- Instead, uou will need to use a new derived-table or a CTE to add a new "logical step" to the query which will SELECTyour base-table'sdate,sale, andbuycolumns, and define the newprofitcolumn.
- ...and the next (outer-er) SELECTcan then define theprofit_prscolumn based on the previous step'sprofitcolumn.
- However, when you do this, the end-result is very verbose and probably harder to maintain:
 
This is what the VIEW looks like when using a new CTE to represent the inner step:
CREATE VIEW dbo.MyView AS
WITH q1 AS (
    SELECT
        a.date,
        a.sale,
        a.buy,
        profit = ( a.sale - a.buy )
    FROM
        dbo.TableA AS a
)
SELECT
    q1.date,
    q1.sale,
    q1.buy,
    q1.profit,
    profit_prs = q1.profit / NULLIF( a.sale, 0.0 )
FROM
    q1;
Whereas if you don't mind the repetition of ( a.sale - a.buy ) you still end-up with a much shorter query:
CREATE VIEW dbo.MyView AS
SELECT
    a.date,
    a.sale,
    a.buy,
    profit     = ( a.sale - a.buy ),
    profit_prs = ( a.sale - a.buy ) / NULLIF( a.sale, 0.0 )
FROM
    dbo.TableA AS a;