0

I want to add value of 3 columns into one new column but there is a problem! problem is that the value of columns is constant!!! but it should change from one column to another one!!!!

SELECT
    query,
    RESPECT,
    INTELLECT,
    STRENGTH,
    SEL,
    EXPERIENCE,
    GUN,
    DOG,
    CAR,
    CASH,
    BANK_CASH,
    STRENGTH + INTELLECT + SEL AS RES2
 FROM P 
5
  • 4
    If the value of your columns is constant, why would you need to store it in a database? Commented Dec 27, 2010 at 4:59
  • 2
    Show the results you are getting and the results you expect, so we can see the difference? Commented Dec 27, 2010 at 5:34
  • 1
    o_O.. kindly provide an example.. Commented Dec 27, 2010 at 6:24
  • 2
    Those are some amusing column names :) Commented Dec 27, 2010 at 6:36
  • 1
    Question, do different guns give strength bonuses? If so, are they a fixed amount or a % of current strength? If the latter you may want to rethink your computed column. Just sayin Commented Dec 27, 2010 at 18:01

1 Answer 1

1

In SQL Server, you have the concept of a computed column which might work for you here. You can define a new column to be an expression of other columns, e.g. in your case:

ALTER TABLE dbo.P
  ADD RES2 AS Strength + Intellect + Sel

Now, your table P would have a new column RES2 that is the sum of Strength, Intellect and Sel. This column will be different for each row - based on the other values for the three fields that make up RES2.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.