473,385 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

What is the best way to build a db to report a total number of true yes/nos'?

I am trying to build a db to report the deficiencies/strengths of security. We have about 1000 criterion that we base these on. I am trying to set it up to where we can specify which criteria they are deficient in, and it will report the total number of deficiencies that section has. i have tried to do this with a yes/no field, and code that looks a little like this:
Expand|Select|Wrap|Line Numbers
  1. Sum(([a1000]+[a1001]+[a1003]+[a1002]+[a1004]+[a1005])*-1)
in order to calculate the total number, but you can see how after even 20 feilds in one table this would get unweildy, let alone across several different tables, because of the 255 field limit that 'MS Access' has.

Is there anything that I am missing? How can I optimize my calculation and db to make it more functional and less error prone. I am used to debugging in c/c++, but SQL is kind of killing me with all of its rules.
Oct 7 '10 #1
5 1364
ADezii
8,834 Expert 8TB
Hopefully I interpreted your request correctly, but here goes. I created a Generic Function for you which will enable you to list the Yes/No Fields by Name in a Table Name passed to the Function, calculates the Number of Yes(s) in each Yes/No Field, then calculates the Percentage of Yes(s) based on the Total Number of Records in the Table. I'll post the Function Definition below, an example of a Sample Call to the Function, and subsequent OUTPUT based on Sample Data (20 Records in tblTest with 15 Fields, 10 of which were Yes/No Type).
  1. Function Code:
    Expand|Select|Wrap|Line Numbers
    1. Public Function fCountYesNos(strTableName As String)
    2. Dim MyDB As DAO.Database
    3. Dim rst As DAO.Recordset
    4. Dim intNumOfFields As Integer
    5. Dim intFldCtr As Integer
    6. Dim lngNumOfRecs As Long
    7. Dim intNumOfYess As Integer
    8. Const conYESNOField As Byte = 1
    9.  
    10. Set MyDB = CurrentDb
    11. Set rst = MyDB.OpenRecordset(strTableName, dbOpenSnapshot)
    12.  
    13. rst.MoveLast: rst.MoveFirst
    14.  
    15. intNumOfFields = rst.Fields.Count
    16. lngNumOfRecs = rst.RecordCount
    17.  
    18. Debug.Print "Field Name", "Yes(s)", "Percent"
    19. Debug.Print "--------------------------------------------"
    20.  
    21. With rst
    22.   For intFldCtr = 0 To intNumOfFields - 1               'Fields Collection indexed at 0
    23.     If .Fields(intFldCtr).Type = conYESNOField Then     'Sorry, Yes/No Field Types only
    24.       intNumOfYess = DCount("*", strTableName, .Fields(intFldCtr).Name & " = True")
    25.       Debug.Print .Fields(intFldCtr).Name, intNumOfYess, Format(intNumOfYess / lngNumOfRecs, "Percent")
    26.     End If
    27.   Next
    28. End With
    29.  
    30. rst.Close
    31. Set rst = Nothing
    32. End Function
  2. Sample Call to Function, passing a Table Name:
    Expand|Select|Wrap|Line Numbers
    1. Call fCountYesNos("tblTest")
  3. OUTPUT based on Sample Data:
    Expand|Select|Wrap|Line Numbers
    1. Field Name    Yes(s)        Percent
    2. --------------------------------------------
    3. Field1         0            0.00%
    4. Field2         5            25.00%
    5. Field3         3            15.00%
    6. Field4         2            10.00%
    7. Field5         5            25.00%
    8. Field6         2            10.00%
    9. Field7         4            20.00%
    10. Field8         3            15.00%
    11. Field9         3            15.00%
    12. Field10        4            20.00%
Oct 7 '10 #2
NeoPa
32,556 Expert Mod 16PB
I would suggest you look at the design of your database to see how you could get the RDBMS (Access in this case) to work for you. A table structure where the table had records for each question within each situation would seem to fit your situation very much better than what you appear to be using now.

From that position your calculations would be a cinch.
Oct 7 '10 #3
I think that gets me about 3/4 of the way there. In the report, I am querying the tables with the deficiencies, and putting that information along side the section information. I am doing it this way in order to print it out and give it to my boss so she can read it and know what section needs the most work. Also, when there was only 10 criterion, i had the tables linked so i could drop down the deficiencies table inside the section info table and modify it there. i added the other tables, and things just sort of blew up. i guess what i am asking is if this will work across multiple tables?

also, as i am not particularly familiar with SQL, do you think that you could define some of the syntax?
Oct 7 '10 #4
NeoPa,

i am not familiar with databases or SQL at all, so i am looking at Access like it is Excel, and while i know that is wrong, i am also thinking like i can modify it like its c/c++. i am now understanding that i am wrong. with that being said, i dont really understand what you are saying about the questions.could you slow down and teach me a little bit? im sorry for my inexperience, and i am really greatful that you are taking your time out to help me!
Oct 7 '10 #5
NeoPa
32,556 Expert Mod 16PB
I will try. A very valuable article on database design generally can be found at Normalisation and Table structures, but I'll post what I can to explain my thoughts anyway.

Assuming you currently have a structure like :
Table = [tblProject]
Expand|Select|Wrap|Line Numbers
  1. Field         Type      Index
  2. ProjectID  Autonumber   PK
  3. Q0001      Boolean
  4. Q0002      Boolean
  5. Q0003      Boolean
  6. ...
You might have records like the following :
Expand|Select|Wrap|Line Numbers
  1. ProjectID  Q0001  Q0002  Q0003  ...
  2. 1034         Y      N      Y
  3. 1062         N      N      Y
Data stored this way is hard to manipulate in the way you require. What I suggest is :
Table = [tblProjectQ]
Expand|Select|Wrap|Line Numbers
  1. Field         Type      Index
  2. ProjectID  Number   FK & 1st part of composite PK
  3. QNumber    Number   FK & 2nd part of composite PK
  4. Q          Boolean
With records like the following :
Expand|Select|Wrap|Line Numbers
  1. ProjectID  QNumber  Q
  2. 1034         1      Y
  3. 1034         2      N
  4. 1034         3      Y
  5. 1034        ...
  6. 1062         1      N
  7. 1062         2      N
  8. 1062         3      Y
  9. 1062        ...
Counting the Y or N values across a particular project would then be a simple aggregate query.

There would also be a [tblProject] and [tblQuestion] tables, but these would contain data pertaining to those items specifically, and not include the values for any questions within any project. EG. The [tblProject] would contain the name of the project and [tblQuestion] probably the security question itself.
Oct 7 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: John | last post by:
hey all..... alright, I am frusterated to the point of throwing my machine out the window (this board went down, trying to find stuff on google, this has been a nightmare) so I hope you guys can...
0
by: krystoffff | last post by:
Hi I would like to paginate the results of a query on several pages. So I use a query with a limit X offset Y to display X results on a page, ok. But for the first page, I need to run the...
5
by: Nick | last post by:
Is there a (better) way to get the toal number of results from a query but still limit them with a LIMIT clause. For example, in a Google search result, it displays 1-100 of 10,000,000 results. Do...
7
by: Egor Shipovalov | last post by:
I'm implementing paging through search results using cursors. Is there a better way to know total number of rows under a cursor than running a separate COUNT(*) query? I think PostgreSQL is bound...
5
by: Quentin Huo | last post by:
Hi: I want to retrieve a set of records from the query like: "SELECT * FROM tVisitors WHERE vTime>'1/1/2004'" And then I will put a part of records into a DataSet by: DataSet ds = new...
0
by: Ray | last post by:
Dear all, I would like to ask how to know the total number of pages of the output crystal report if I am using ReportDocument. Thanks a lot, Ray
2
by: patang | last post by:
I found the following to count the total number of VISIBLE rows of datagrid datagrid.visiblerowcount How do we count the total number of ACTUAL (not just visible) rows of datagrid? Thanks...
4
by: MA | last post by:
Hi, How to access the total number of child nodes from a parent node. For example, I would like to get the total number of child nodes from <parent1and <parent2node. The SelectNodes method...
0
by: Jon Bowlas | last post by:
Many thanks for all your reponses, much appreciated. I'll get back to you on which is the best for me. BTW - yes John thats exactly what I wanted. Cheers Jon
2
by: alwaali | last post by:
Hi I need help please This is my project and i need a help to solve it with you A page of text is to be read and analyzed to determine number of occurrences and locations of different words. The...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.