Solved

Handling very long strings

Posted on 2002-05-16
7
148 Views
Last Modified: 2010-05-02
Hello Experts:

I have seem to run into a problem that I don't know how to handle.

I am using Sql 7.0 for the database backend, and I store very long strings in a field defined as text.  When I pull this data into a string variable, it only retrieves about 1300 characters of data.  Im not sure if its the field definition or the variable definition that I'm having a problem with.  As long as the data is smaller than 1300 characters, it works fine.

Any ideas?

Data is stored as such:

65000,65001,65002,65003,......

I pull this into a string variable then run a sql statement as such:

Select * from tablename where fieldname in (Variable).
0
Comment
Question by:escheider
7 Comments
 
LVL 5

Accepted Solution

by:
bob_online earned 50 total points
ID: 7014102
That's not what is happening.

when you use the In (list of items) syntax you are limited to 255 values in the list.  Note that 1300 / 5 = 260 so when you say about 1300 characters my guess is that it's really 1275 which, with 5 digit numbers, results in 255 items.

You're going to have to do something like this:

select * from tablename where fieldname in (Variable1) or fieldname in (Variable2) or fieldname in (variable3).

I'm assuming you're actually concatenating the string such as

"Select * from tablename where fieldname in (" & Variable1 & ") or fieldname in (" & Variable2 & ")"

If you know the max number of values, you can just dim the number of variables you need at design time.  Otherwise, I would use an array of strings and dynamically dimension it on the fly.  Then do something like

SQL = "Select * from tablename where "
For I = 1 to arrNames.Ubound
   SQL = SQL & "Fieldname in (" & arrNames(I - 1) & ") Or "
Next
SQL = Left$(SQL, Len(SQL) - 4) ' to cut of the last " or "
0
 
LVL 5

Expert Comment

by:bob_online
ID: 7014123
To continue, you can build the array like this

done = false
ArrayIndex = -1
While not done
   redim preserve arrNames(arrNames.Ubound + 1)
   ArrayIndex = ArrayIndex + 1
   arrNames(ArrayIndex) = Left$(StringFromDatabase, 1275)
   StringFromDatabase = Mid$(StringFromDatabase, 1276)
   If Len(StringFromDatabase = 0 Then
      Done = True
   End If
Wend
0
 
LVL 4

Expert Comment

by:trkcorp
ID: 7014128
ASSUMING ADO:
You probably need to use the GetChunk method for retrieving the data... This is well documented.  Look up ADO/data types/managing long data types in your help files
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 5

Expert Comment

by:bob_online
ID: 7014130
Finally, the 1275 value in my parsing routine won't work because it isn't allow for commas but you can easily calculate the corrrect value.

0
 
LVL 1

Expert Comment

by:eosu
ID: 7023677
don't use getchunck - use ADO streams.
0
 
LVL 4

Author Comment

by:escheider
ID: 7060375
Sorry its been awhile since I've checked on this, my wife is pregnant and haven't dedicated time to this site.

eosu, please give me an example on ADO streams..
0
 
LVL 4

Author Comment

by:escheider
ID: 7063837
Decided to close this question.  I used your example and it works just fine...thanks for your time and input
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…

821 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