Solved

SQL Statement: CountOfSummaryItem

Posted on 2003-12-05
10
379 Views
Last Modified: 2010-05-01
Hello All,

Is there anyway to ASC, DESC the CountOfSummaryItem in this sql?:

s_Sql = "SELECT DAuthor, Count(DAuthor) As CountOfSummaryItem, _
        (Count(*)/(Select count(*) FROM tbl_Records_DR)) as Percentage _
        From tbl_Records_DR GROUP BY DAuthor Order BY DAuthor;"

Thanks guys. ADawn
0
Comment
Question by:ADawn
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 5

Expert Comment

by:rajaamirapu
ID: 9882092
s_Sql = "SELECT DAuthor, Count(DAuthor) As CountOfSummaryItem, _
        (Count(*)/(Select count(*) FROM tbl_Records_DR)) as Percentage _
        From tbl_Records_DR GROUP BY DAuthor Order BY CountOfSummaryItem;"
0
 

Author Comment

by:ADawn
ID: 9882371
rajaamirapu

I've tried this. It doesn't work! I receive the error message:

"No value given for one or maore required parameters."
0
 
LVL 1

Expert Comment

by:carpe-diem
ID: 9882396
Or
s_Sql = "SELECT DAuthor, Count(DAuthor) As CountOfSummaryItem, _
        (Count(*)/(Select count(*) FROM tbl_Records_DR)) as Percentage _
        From tbl_Records_DR GROUP BY DAuthor Order BY DAuthor, CountOfSummaryItem DESC;"
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 1

Expert Comment

by:carpe-diem
ID: 9882418
How are you using this sql statement? Is it part of a data environment for example?
0
 

Author Comment

by:ADawn
ID: 9882431
carpe-diem

Same error message:

"No value given for one or maore required parameters."

ADawn
0
 
LVL 5

Expert Comment

by:rajaamirapu
ID: 9882559
Can you give the error code
0
 
LVL 9

Expert Comment

by:p_sie
ID: 9882579
s_Sql = "SELECT DAuthor, Count(DAuthor) As CountOfSummaryItem, _
        (Count(*)/(((Select count(*) FROM tbl_Records_DR)))) as Percentage _
        From tbl_Records_DR GROUP BY DAuthor Order BY DAuthor, CountOfSummaryItem DESC;"

Try adding extra (( )) around the subquery, I know I always use them with subqueries, otherwise errors can occur!
Don't know if this will resolve your problem.
0
 

Accepted Solution

by:
ROTRTechTeam earned 50 total points
ID: 9884278
It is really easy, but you need to think about what you are wanting to order by.  You say you want to order by CountOfSummaryItem, but to SQL there is no such column.  That is why the other answers you've gotten won't work.  Remember that those aliases are just for the column title.  In your case you can accomplish what you want as follows:

s_Sql = "SELECT DAuthor, Count(DAuthor) As CountOfSummaryItem, _
        (Count(*)/(Select count(*) FROM tbl_Records_DR)) as Percentage _
        From tbl_Records_DR GROUP BY DAuthor Order BY DAuthor ORDER BY Count(DAuthor);"

You can add ASC or DESC after the "ORDER BY Count(DAuthor)" to order ascending or descending.


0
 

Author Comment

by:ADawn
ID: 9888083
ROTRTechTeam

Thanks for the great information. However, please note that you have two Order BY clauses which caused an error. I removed Order BY DAuthor (keeping: ORDER BY Count(DAuthor)) and the SQL works great.

This comment is for others that may want to use your GREAT works!

Thanks,

ADawn
0
 

Expert Comment

by:ROTRTechTeam
ID: 9888418
Whoops!  I copied your SQL and added my order by at the end.  Sorry about that, but thanks for the compliments!  Glad it worked for you!
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Convert VB6 MSXML2.ServerXMLHTTP process to C# 2 46
Added a column screws up code 5 57
Zip Folders Using Chilkat Routines 1 38
Automatic Email Reminder 4 37
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question