To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Part 10 of the Visual Basic .NET 2010 Express Tutorial Complete!
How to Use the Visual Studio Code Analysis Tool FxCop
Article :: Interview with Andrei Alexandrescu (Part 3 of 3)
Introducing Visual Studio LightSwitch
Visual Studio LightSwitch Beta 1 is Available



Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier

Reply Post New Thread
 
Thread Tools Display Modes
Old Feb 14th, 2004, 02:48 PM   #1
azrina
Lively Member
 
Join Date: Jan 04
Posts: 100
azrina is an unknown quantity at this point (<10)
sql statement

I generate report with Data Report without using Data Environment.

I have table like below
weight(NoRujukan,Sampel)

I want the data of the table group by NoRujukan.

My sql statement is,

VB Code:
  1. rs.Open "SELECT weight.NoRujukan, weight.Sampel FROM weight group by NoRujukan", conn, adOpenStatic, adLockOptimistic

But, when execute, the error of the sql is something about aggregate function.
Wht does it mean?

Can anyone give me a sample of how to group data report?
azrina is offline   Reply With Quote
Old Feb 14th, 2004, 03:33 PM   #2
BruceG
PowerPoster
 
BruceG's Avatar
 
Join Date: May 00
Location: New Jersey (USA)
Posts: 2,560
BruceG is a jewel in the rough (200+)BruceG is a jewel in the rough (200+)BruceG is a jewel in the rough (200+)
Aggregate functions are functions like SUM, COUNT, AVG, etc. When doing a GROUP BY query, any fields in the SELECT clause that are not included in the GROUP BY clause must use an aggregate function. For example, your query could be corrected as follows:
VB Code:
  1. rs.Open "SELECT weight.NoRujukan, [b]SUM(weight.Sampel)[/b] FROM weight group by NoRujukan", conn, adOpenStatic, adLockOptimistic
__________________
"It's cold gin time again ..."

Check out my website here.
BruceG is offline   Reply With Quote
Old Feb 14th, 2004, 11:10 PM   #3
azrina
Lively Member
 
Join Date: Jan 04
Posts: 100
azrina is an unknown quantity at this point (<10)
Quote:
Originally posted by BruceG
VB Code:
  1. rs.Open "SELECT weight.NoRujukan, [b]SUM(weight.Sampel)<b>Aggregate functions are functions like SUM, COUNT, AVG, etc. When doing a GROUP BY query, any fields in the SELECT clause that are not included in the GROUP BY clause must use an aggregate function. For example, your query could be corrected as follows:
  2. </b> FROM weight group by NoRujukan", conn, adOpenStatic, adLockOptimistic
[/b]
I use the code above and there is error which is --->DataField 'Sampel' not found.

If i didnt use the "SUM" and "GROUP BY", the report can be displayed.

Why is that so?
Thank You in advance.
azrina is offline   Reply With Quote
Old Feb 15th, 2004, 02:14 AM   #4
leinad31
PowerPoster
 
Join Date: Nov 02
Location: Manila
Posts: 7,464
leinad31 is a glorious beacon of light (400+)leinad31 is a glorious beacon of light (400+)leinad31 is a glorious beacon of light (400+)leinad31 is a glorious beacon of light (400+)leinad31 is a glorious beacon of light (400+)leinad31 is a glorious beacon of light (400+)
Quote:
Originally posted by azrina
I use the code above and there is error which is --->DataField 'Sampel' not found.

If i didnt use the "SUM" and "GROUP BY", the report can be displayed.

Why is that so?
Thank You in advance.
Sum is an expression hence the result will be automatically named Expr1 unless you indicate the fieldname/alias it will use. Since your using the fieldname in the datareport control's datafield property, indicate the alias.

VB Code:
  1. 'Query
  2. rs.Open "SELECT weight.NoRujukan, SUM(weight.Sampel) [b]AS AGGR_Sampel[/b] FROM weight group by NoRujukan", conn, adOpenStatic, adLockOptimistic
  3. 'In datareport
  4. DataReport1.Sections("Details").Controls("txtSampel").DataField = "AGGR_Sampel"
leinad31 is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic 6 and Earlier


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

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:24 AM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.