Home Forums SQL Server 2008 T-SQL (SS2K8) Using Results from one column to calculate another column RE: Using Results from one column to calculate another column

  • If all the columns are from a single table, you definitely should created a computed column that has the computation: that way, the definition is in only one place. You do not have to persist it, although you could -- you can base that on how often you use it vs how much overhead it really is to calculate vs the bytes needed to store it.

    Whether persisted or not, you can use it in a SELECT just like any other column. For example:

    ALTER TABLE dbo.yourtablename

    ADD Results1 AS Col1 * 1.57 / Col2 * CASE WHEN Col3 = 'A' THEN Col4 ELSE Col5 END

    Then your query can be:

    SELECT

    Results1, Colx / Results1 AS ...

    FROM dbo.yourtablename

    WHERE

    Results1 >= 9.75

    GROUP BY

    Results1

    ORDER BY

    Results1

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.