Microsoft Access Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft Access Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old December 7th, 2003, 01:46 PM
Petu Petu is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 14 Petu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to Petu
Aggregate function with Select Statement

How do I combine the following statements:

SqlJunk = " SELECT SUM(MSD+Methods+Analysis+Architectures+Models+Stud io+Elective1+Elective2+Elective3) As PersonTotals FROM tblpersons "

SqlJunk = "SELECT FirstName, LastName, WeekNo, ProgramName, StudioTeamName FROM tblpersons"

I tried UNION but didn't work

Thanx

Reply With Quote
  #2  
Old December 7th, 2003, 03:36 PM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 12
SELECT FirstName, LastName, WeekNo,
ProgramName, StudioTeamName, 0 AS PersonTotals FROM tblpersons
UNION
SELECT "" as FirstName, "" AS LastName, "" AS WeekNo, "" AS ProgramName, "" AS StudioTeamName, SUM(MSD+Methods+Analysis+Architectures+Models+Stud
io+Elective1+Elective2+Elective3) As PersonTotals FROM tblpersons

This is assuming that your first query list statement is a summary total for the second, based on your reference to using a UNION

To use a UNION you need to same number of columns in each query and they should be the same data Type in each corresponding column.


OR

SELECT FirstName, LastName, WeekNo, ProgramName, StudioTeamName,(MSD+Methods+Analysis+Architectures +Models+Stud
io+Elective1+Elective2+Elective3) As PersonTotals FROM tblpersons

This is assuming you want together on each row.



Let me know if it was someting different that you wanted

S-

Reply With Quote
  #3  
Old December 7th, 2003, 06:40 PM
Petu Petu is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 14 Petu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to Petu
FirstName,LastName,ProgramName and StudioTeamName are text fields and the rest are numbers....so what I'm trying to do is SUM the numbers and write the (Users FirstName,LastName,......).

All this data is in one record i.e. for a certain user.....the action that a user take is to search for his record and get the totals with his/her First and lastname.....

In the meantime I'll check what you send me.

Thanx

Reply With Quote
  #4  
Old December 7th, 2003, 07:01 PM
Petu Petu is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 14 Petu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to Petu
WHEN I USE THIS STATEMENT(the one you send me)

If Request.Form("TypeSearch") = "User_Id" Then
SqlJunk = "SELECT FirstName, LastName, WeekNo, ProgramName, StudioTeamName,(MSD+Methods+Analysis+Architectures +Models+Studio+Elective1+Elective2+Elective3) As PersonTotals FROM tblpersons"
SqlJunk = SqlJunk & " WHERE User_Id=" & Request.Form("DaInBox")
End If

I GET THE FOLLOWING RESULTS

Here are the results of your search:
FirstName LastName WeekNo ProgramName StudioTeamName
Maggy Lae 1 MSE PMC
PersonTotals =

PersonTotals doesn't have a value. I want to get the SUM of all those fields.

Reply With Quote
  #5  
Old December 8th, 2003, 09:31 AM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 12
Can you post a sample of your DB with Data?

S-

Reply With Quote
  #6  
Old December 8th, 2003, 12:09 PM
Petu Petu is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 14 Petu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via Yahoo to Petu
Thanx for your help....the only thing I was missing was to write out the PersonTotal value from the ResultSet to the ASP page. The way I was doing it was not writing the ResultSet thats why I was getting an empty "PersonTotals"

Thanx

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft Access Help > Aggregate function with Select Statement


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway