Solved

SQL Statement: CountOfSummaryItem

Posted on 2003-12-05
10
381 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

735 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