User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 391,609 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,620 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser:
Views: 636 | Replies: 3
Reply
Join Date: May 2008
Posts: 2
Reputation: Ms Linda is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Ms Linda Ms Linda is offline Offline
Newbie Poster

View Help and calculations

  #1  
Jun 24th, 2008
Good day all! Need assistance with the following:

I a table that houses information and want to create calculations based on the info.
I have created a view to perform one of the calcs.
Now I want to sum columns that will put info into another field that I can than perform another function. Unfortunately I keep getting aggregate errors that I need to add field in group by or select statement. I can do one, but not others. After I do one I then need to take that field and perform another calculation.

Example
SUM (Column A) AS TotalColumnA
SUM (Column B) AS TotalColumnB

Then I need to divide Column A by Column B to get to AS Column C
etc....

Since this is a vew can it be done? To further complicate this I need to be able to choose a "between date" end user fills in the begin date and end date.

YIKES!!! I have manual and have been trying to figure out, but I am brain dead trying many different things.

Your expertise would be very appreicated on how I should set this up in MS SQL. If you need a copy of what I am doing... happy to send along.

Thank you!!!!!!!!!!!!!!!!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2008
Posts: 295
Reputation: tesuji is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 41
tesuji tesuji is offline Offline
Posting Whiz in Training

Re: View Help and calculations

  #2  
Jun 24th, 2008
hi,
this could be a solution:
  1. SELECT SUM (COLUMN A) AS TotalColumnA, SUM (COLUMN B) AS TotalColumnB,
  2. TotalColumnA / TotalColumnB AS TotalColumnC FROM yourTable;

If you want to select further columns, for example ColumnX together with results from aggregate functions, you need group by clause:
  1. SELECT ColumnX, SUM (ColumnA) AS TotalColumnA, SUM (ColumnB)
  2. AS TotalColumnB, TotalColumnA / TotalColumnB AS TotalColumnC
  3. FROM yourTable GROUP BY ColumnX;

Maybe you post your complete SQL select statement, also view definition, possibly I might then be able to give better advice.

krs,
tesu
Reply With Quote  
Join Date: May 2008
Posts: 2
Reputation: Ms Linda is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Ms Linda Ms Linda is offline Offline
Newbie Poster

Re: View Help and calculations

  #3  
Jun 24th, 2008
Thank you so much for quick response!!! I tried your formula and I'm sure it'scorrect, but my dilemma is a bit more complex. I'm not sure if this has something to do with it, but I have created a view to get totals for other columns,and am then creating this other view to pull them together and run totals and new formulas on those totals. I have attached a screen print to show you what I am doing. Since I am fairly new to all of this I hope I'm not in over my head and you can give me some help.

Everything I am trying to do is in a spreadsheet which is very cumbersome and not productive, hence why I am creating a database. If you have any questions you are welcome to email me at lfarruggia@athleticausa.com.

I would be very appreciative for your help.

Again my sincere thanks to put me on the right track! I have a sql book, but it's just not detailed enough to help me or I'm just too plain stupid to understand it! smile...
Attached Files
File Type: doc ResponsetoDaniWeb.doc (108.5 KB, 2 views)
Reply With Quote  
Join Date: Apr 2008
Posts: 295
Reputation: tesuji is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 41
tesuji tesuji is offline Offline
Posting Whiz in Training

Re: View Help and calculations

  #4  
Jun 30th, 2008
Hi again,

well, I have got some problems understanding your screen shots. Wouldn't it be easier you post your sql code for tables and view creations? I know, if select statements are getting more and more complex, creating views or stored procedure is obviously an appropriate vehicle to get some provisional results where further results might be drawn from. Do you ever thought of using WITH clause?

Maybe I will be able to give you further advice when I would have seen the create-view and create-tables code.

krs,
tesu
Last edited by tesuji : Jun 30th, 2008 at 5:56 pm.
Information is moving—you know, nightly news is one way, of course, but it's also moving through the blogosphere and through the Internets. I promise you I will listen to what has been said here, even though I wasn't here. Ann and I will carry out this equivocal message to the world. I'm the master of low expectations.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb MS SQL Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the MS SQL Forum

All times are GMT -4. The time now is 12:14 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC