By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,101 Members | 1,335 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,101 IT Pros & Developers. It's quick & easy.

Maximum 1024 Characters in a query

P: 73
I tried to do an iif statement containing IIF(([Q1])Like "1", all the way to Q50 (having 50 questions) and was doing a Count function to count where all of these were a 1 and the query keeps stating that it is too long max 1024 characters and will be tuncated. Any ideas on how to write this in VB or another way around this?
Sep 3 '08 #1
Share this Question
Share on Google+
4 Replies


Expert Mod 2.5K+
P: 2,545
More questions than answers for you Supermansteel. Firstly, are you trying to determine whether the answers to all 50 questions are the same? Secondly, is each answer represented by a number, or by a string (text) value? Thirdly, is the value 1 the only possible answer other than 0, say?

You are using the 'like' operator intended for text values, but it is intended for partial matches using 'like "*somechars*"' syntax. Your use of 'like' is just the same as using '=', but takes far more characters.

If what you want to do is some form of brute-force check that all 50 answers are set to the value 1 (where 1 is the only value possible other than 0), returning a 1 if so and a 0 otherwise, then the shortest form I can think of would depend on those values being numeric, not text strings. You would have to include all the field names in your statement; I have abbreviated mine for clarity.

IIF([Q1]+[Q2]+[Q3] ... [Q49]+[Q50] = 50, 1, 0)

If your values are text and not numbers you would need to use

IIF(([Q1]="1") AND ([Q2]="1") AND ([Q3]="1") ... AND ([Q49]="1") AND ([Q50]="1"), 1, 0)

If your values are numbers but they can also take other values than 1 you need to use another ANDed version:

IIF(([Q1]=1) AND ([Q2]=1) AND ([Q3]=1) ... AND ([Q49]=1) AND ([Q50]=1), 1, 0)

There are simpler ways to accomplish the calculation in VBA, but rather than go into these at present (as calculating such a value is one thing, doing something useful with it another) you really need to assist us by being a bit clearer in what you are asking of us. I await your next post with interest.

-Stewart
Sep 3 '08 #2

P: 73
I will back track....My table has 150 fields. I don't know if this is the best way of doing what i did, but here it goes. Most of the fields in my table are state, branch, account#,and more account information. Then at the end of my table, I have 50 number fields, one for every question that i labeled Q1 thru Q50. These essentially are put are my Form as an Option Group as Yes=1, No=2 to each of the 50 Questions. Every time someone would click Yes it would be listed as an exception to Policy and was trying to create a count function to count how many exceptions during the month. (Listed below). This code below is actually from a second table I have 250 fields and 99 Questions and this is the one that keeps giving me an error. but there are suppose to be 99 questions and won't let me add anymore to the query.
Expand|Select|Wrap|Line Numbers
  1. SELECT Originations_RE_US.Sample_Month, Count(Originations_RE_US.Acctno) AS [TO]
  2. FROM Originations_RE_US
  3. WHERE (((IIf([Q1]=1 Or [Q2]=1 Or [Q3]=1 Or [Q4]=1 Or [Q5]=1 Or [Q6]=1 Or [Q7]=1 Or [Q8]=1 Or [Q9]=1 Or [Q10]=1 Or [Q11]=1 Or [Q12]=1 Or [Q13]=1 Or [Q14]=1 Or [Q15]=1 Or [Q16]=1 Or [Q17]=1 Or [Q18]=1 Or [Q19]=1 Or [Q20]=1 Or [Q21]=1 Or [Q22]=1 Or [Q23]=1 Or [Q24]=1 Or [Q25]=1 Or [Q26]=1 Or [Q27]=1 Or [Q28]=1 Or [Q29]=1 Or [Q30]=1 Or [Q31]=1 Or [Q32]=1 Or [Q33]=1 Or [Q34]=1 Or [Q35]=1 Or [Q36]=1 Or [Q37]=1 Or [Q38]=1 Or [Q39]=1 Or [Q40]=1 Or [Q41]=1 Or [Q42]=1 Or [Q43]=1 Or [Q44]=1 Or [Q45]=1 Or [Q46]=1 Or [Q47]=1 Or [Q48]=1 Or [Q49]=1 Or [Q50]=1 Or [Q51]=1 Or [Q52]=1 Or [Q53]=1 Or [Q54]=1 Or [Q55]=1 Or [Q56]=1 Or [Q57]=1 Or [Q58]=1 Or [Q59]=1 Or [Q60]=1 Or [Q61]=1 Or [Q62]=1 Or [Q63]=1 Or [Q64]=1 Or [Q65]=1 Or [Q66]=1 Or [Q67]=1 Or [Q68]=1 Or [Q69]=1 Or [Q70]=1 Or [Q71]=1 Or [Q72]=1 Or [Q73]=1 Or [Q74]=1 Or [Q75]=1 Or [Q76]=1 Or [Q77]=1 Or [Q78]=1 Or [Q79]=1 Or [Q80]=1 Or [Q81]=1 Or [Q81]=1 Or [Q82]=1 Or [Q83]=1 Or [Q84]=1 Or [Q85]=1 Or [Q86]=1 Or [Q87]=1,"1","2")) ALike "1"))
  4. GROUP BY Originations_RE_US.Sample_Month;
I don't know if creating the table with all of these fields to store the questions is the most efficient way of getting this done, however, I have thought about seperating these two things and have a table to store all of the account information and have a Questions table to house all of the Questions and have a Main table to pull them together, but wasn't fully sure how to do it that way and if that way would be the most efficient and easiest to modify down the road.


Any input would be greatly appreciated. Please let me know if you do not understand anything that i have stated.

Thanks,

Matt
Sep 3 '08 #3

Expert Mod 2.5K+
P: 2,545
Sorry, but your table design is not just inefficient. Inclusion of 50 questions breaches first normal form rules about separation of repeating groups into their own tables. Relational tables rarely have more than a few tens of fields at most - so 150 fields before your questions were added says straight away that your table design is not normalised. I guess it looks more like an Excel free-form table, containing many entities which should be split out into their own tables.

You can't work on unnormalised data with a relational database and get anything like the flexibility and performance you could with normalised data. You are also throwing away the power of the database engine, which is designed to optimise table performance where one-to-many relations have been designed and enforced from the start.

As general advice on table design please see the following HowTo article on Database Normalisation and Table Structures.

In terms of the question problem you should have at least a separate question table, and a response table linking account and question. To add to your plight your individual response fields should simply have been boolean (yes/no) values, not numerics taking the value 1 and 2.

I have corrected the where clause below as far as I can, but your design problems have already taken you past Access's 255 field limits (the reason you cannot add more questions to your table).

You need to redesign your tables from scratch. As it is your table design I am sorry to say is not just inefficient it is completely unmaintainable, and there is no point in trying further workarounds...

-Stewart

Expand|Select|Wrap|Line Numbers
  1. SELECT Originations_RE_US.Sample_Month, Count(Originations_RE_US.Acctno) AS [TO]
  2. FROM Originations_RE_US
  3. WHERE ([Q1]=1 Or [Q2]=1 Or [Q3]=1 Or [Q4]=1 Or [Q5]=1 Or [Q6]=1 Or [Q7]=1 Or [Q8]=1 Or [Q9]=1 Or [Q10]=1 Or [Q11]=1 Or [Q12]=1 Or [Q13]=1 Or [Q14]=1 Or [Q15]=1 Or [Q16]=1 Or [Q17]=1 Or [Q18]=1 Or [Q19]=1 Or [Q20]=1 Or [Q21]=1 Or [Q22]=1 Or [Q23]=1 Or [Q24]=1 Or [Q25]=1 Or [Q26]=1 Or [Q27]=1 Or [Q28]=1 Or [Q29]=1 Or [Q30]=1 Or [Q31]=1 Or [Q32]=1 Or [Q33]=1 Or [Q34]=1 Or [Q35]=1 Or [Q36]=1 Or [Q37]=1 Or [Q38]=1 Or [Q39]=1 Or [Q40]=1 Or [Q41]=1 Or [Q42]=1 Or [Q43]=1 Or [Q44]=1 Or [Q45]=1 Or [Q46]=1 Or [Q47]=1 Or [Q48]=1 Or [Q49]=1 Or [Q50]=1 Or [Q51]=1 Or [Q52]=1 Or [Q53]=1 Or [Q54]=1 Or [Q55]=1 Or [Q56]=1 Or [Q57]=1 Or [Q58]=1 Or [Q59]=1 Or [Q60]=1 Or [Q61]=1 Or [Q62]=1 Or [Q63]=1 Or [Q64]=1 Or [Q65]=1 Or [Q66]=1 Or [Q67]=1 Or [Q68]=1 Or [Q69]=1 Or [Q70]=1 Or [Q71]=1 Or [Q72]=1 Or [Q73]=1 Or [Q74]=1 Or [Q75]=1 Or [Q76]=1 Or [Q77]=1 Or [Q78]=1 Or [Q79]=1 Or [Q80]=1 Or [Q81]=1 Or [Q81]=1 Or [Q82]=1 Or [Q83]=1 Or [Q84]=1 Or [Q85]=1 Or [Q86]=1 Or [Q87]=1)
  4. GROUP BY Originations_RE_US.Sample_Month;
Sep 3 '08 #4

P: 73
Thanks for the advice. I will have to go back to the drawing board on this. I am usually alot better with table designing, I don't know why I was trying to do this the hard way.

Matt
Sep 3 '08 #5

Post your reply

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