By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,806 Members | 1,837 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,806 IT Pros & Developers. It's quick & easy.

Updating Column Data on the Fly?

P: n/a
Hey...newbie question: I've got three columns in my database, the
third of which is blank right now, and I need it to equal the value of
column one minus column two. While I can accomplish this in the .aspx
page with a subroutine, I want to do it in SQL Server so I can simply
read the data in the page and not have to do any calculations. Help
please? Thanks.

Erik

Jul 23 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Best not to put the third column in the table. Just calculate the result in
a SELECT statement when you query the table:

SELECT col1, col2, col1-col2 AS col3,
FROM YourTable
WHERE ...

--
David Portas
SQL Server MVP
--
Jul 23 '05 #2

P: n/a
Excellent. Thanks David.

Erik

Jul 23 '05 #3

P: n/a
Another quick question -- if I want to SUM values in col1 WHERE a
certain condition exists before subtracting col2 from it, I run into an
"Aggregate function" error...is there a way around that?

Jul 23 '05 #4

P: n/a
Hi

You probably want a subquery see the topic "Subquery Fundamentals" in Books
Online.

John

<er**********@hotmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
Another quick question -- if I want to SUM values in col1 WHERE a
certain condition exists before subtracting col2 from it, I run into an
"Aggregate function" error...is there a way around that?

Jul 23 '05 #5

P: n/a
That did the trick. Thanks!

Erik

Jul 23 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.