I have a computed column called Cost that returns money.
I want to have another column that returns (Cost * 2), but it doesn’t allow me.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Computed columns cannot reference other computed columns. Though you ought to be able to just repeat the expression you would like to reference. From MSDN:
I should also add that if this were to work as you would hope, it would present all kinds of new issues you’d have to deal with. Presently, updates across many columns/rows occur in parallel and atomically.
Therefore, it wouldn’t make sense to use a computed column in your calculation because it wouldn’t exactly have a value…yet. If anything, you’d be using an old, un-updated value.
If you really wanted to avoid duplicating the expression, you could do this in a trigger, though I strongly urge you not do that. Triggers are no fun and should only be used by very savvy people in rare cases.