|
-
Feb 14th, 2004, 03:48 PM
#1
Thread Starter
Lively Member
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:
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?
-
Feb 14th, 2004, 04:33 PM
#2
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:
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.
-
Feb 15th, 2004, 12:10 AM
#3
Thread Starter
Lively Member
Originally posted by BruceG
VB Code:
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:
</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.
-
Feb 15th, 2004, 03:14 AM
#4
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:
'Query
rs.Open "SELECT weight.NoRujukan, SUM(weight.Sampel) [b]AS AGGR_Sampel[/b] FROM weight group by NoRujukan", conn, adOpenStatic, adLockOptimistic
'In datareport
DataReport1.Sections("Details").Controls("txtSampel").DataField = "AGGR_Sampel"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|