Computed Field

I have SQL server 2005 and i need to create a computed field in a table.
I need the computed field to add the first 2 columns in the table (which are of type int)
i.e. colA, colB, colC = colA + colB.

Thanks
fred2k3Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Patrick MatthewsCommented:
ALTER TABLE SOmeTable ADD ColumnName AS colA + colB
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fred2k3Author Commented:
thanks put can you specify the new fields type?
0
Patrick MatthewsCommented:
fred2k3 said:
>>thanks put can you specify the new fields type?

That will be determined by the expression you use.  So, if colA and colB are both int, then so will the computed
column be treated as an int.

If you wanted, say, a numeric type, you would need to force a type conversion in the expression:

ALTER TABLE SOmeTable ADD ColumnName AS CONVERT(numeric(10, 2), colA) + CONVERT(numeric(10, 2), colB)
0
fred2k3Author Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.