Computed column question

  • Ok... here's the deal. I want to create a computed column that takes a base value in one table, and increments in the computed column table. For instance, in table a I have a base value of 100. In table b, when I insert a row, I want a computed column that takes the latest value and increments it by one, or if there isn't a latest value, it takes just the base value (100). Does anyone have any pointers on how to do this? :blink:

  • Can't be done... computed columns cannot refer to other tables.

    You might be able to use a trigger to accomplish this. Why do you need to do this?

    --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)

  • Yikes. So I'm going to have to store redundant data, eh? I guess I could store the base value in the same table as the computed column. I wish there were a way to do it without that though.

  • No... redundant data is not necessary. Like I said, you could use a trigger to pull this off.

    Just curious... why do you want to do this? What is in the 2 tables that requires it... there may be another way...

    --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