Computed column formula with join

  • I have a column c1 in a table T1, there is another table t2 with column c2.

    I am required to prepare a formula for a computed column in t2.

    Formula will check that if c2 is less than c1 then computed value will be 0, and if c2 > = c1 then computed value will be 1.

    How to prepare such formula with join between t1 and t2.

    DBDigger Microsoft Data Platform Consultancy.

  • Hello,

    You would probably want to create the Computed Column from a Case statement based on column c2, with the if/else logic comparing it to column c1.

    Regards,

    John Marsh

    www.sql.lu
    SQL Server Luxembourg User Group

  • A computed column cannot be used as defining expression may only reference base columns within the same table.

    You will need to add a physical column and then use a trigger to maintain the value.

    SQL = Scarcely Qualifies as a Language

  • Like Carl said... can't be done by a computed column... but, you could use a view for this. Carl also suggested that you could use a trigger and that would work, as well.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply