SQL Server 2005 query to get the average

75 pts.
Tags:
Microsoft Windows Server 2003
SQL
SQL queries
SQL Server 2005
Hi, I'm using MSSql 2005 on Windows 2003 Server. I need some assistance to write a query to get the average of two columns and write the value to a third coulmn. All the transactions is in one table. Basically it is column 1 + column 2 devide by two = column 3 Thank you, George

Answer Wiki

Thanks. We'll let you know when a new response is added.

You you do the match pretty much like you wrote it above.

<pre>SELECT (Column1+Column2)/2 as Column3
From YourTable</pre>

<pre>Problem is that I run the query and it dispays my value, but asoon as I query that column the value is NULL.</pre>

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Kccrosser
    Are you asking for a "statement" that sets the third column value to the average of the other two columns? That isn't a "query" - you need to use an Update statement: update mytable set column3 = (column1 + column2)/2; A query does not change the values in the underlying tables. Note - you may want to look at functions like "Round" or "Floor" if you want the average to be of a specified precision, or an integer value. update mytable set column3 = round((column1+column2)/2, 2);
    3,830 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following