October 29, 2010 at 1:08 pm
Hello,
I created a view from a select against a database table. I added a new column (QtyTotal) to the view that I want to capture the SUM of two fields in each row.
What I have is a database table that has two rows that are almost identical with the exception of the QTY field. For some reason, when users enter totals into the database, the total gets split into two rows. Example is if a user enters a quantity of 100, the table will store that data in two rows with the QTY field showing 99 in one row and 1 in the second row. What I want to do is create a calculation on a new column (QtyTotal) that will SUM the QTY fields of the two rows so that I have a field that shows a QtyTotal of 100.
I am new to db administration (as you might be able to tell from my post) and am wondering how to accomplish this OR if there is a better way to achieve a similar result.
Thanks for your help.
October 29, 2010 at 3:13 pm
SUM() is an aggregate function.
You need to group your data by using GROUP BY in your query. Please have a look at BOL (BooksOnLine, the SQL Server help system usually installed with SQL Server), section SUM().
It'll include samples, too.
October 29, 2010 at 3:15 pm
Thanks Lutz.
I'll give it a shot.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply