Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL: Statement too long.  FoxPro 6.0 SQL querry.....

Posted on 2004-04-21
8
Medium Priority
?
445 Views
Last Modified: 2013-12-25
Hi, and thanks in advance for any help.

I have a set of FoxPro free tables that are linked to each other through keys.  So, I first populate my first Recordset with an SQL table that matches the date the user puts in.  In that table there are the File Id's that allow finding the correct data in each of the other tables.  So, I just loop through all the file ID's in the first table and create an SQL querry in a loop to get the data in the other tables.  This works great until I get too many records, and when that happens I get this Error.  Even on a Querry whos length is >5000.  :S  Here is a rough loop to show what I'm doing.  Kinda new to the whole programming thing, so if you could keep the answers kinda simple I would appreciate it.

MainSqL = "where (FILE_ID = '"
FUN.Recordset.MoveFirst
For I = 1 To FUN.Recordset.RecordCount
    If I = FUN.Recordset.RecordCount Then
        MainSqL = MainSqL & FUN.Recordset.Fields("file_id") & "')"
        Exit For
    Else
        MainSqL = MainSqL & FUN.Recordset.Fields("file_id") & "') OR (FILE_ID = '"
End If
    FUN.Recordset.MoveNext
Next

GEN.RecordSource = "SELECT * FROM GEN " & MainSqL
GEN.Refresh
DOC.RecordSource = "SELECT * FROM DOC " & MainSqL
DOC.Refresh

(EDIT:)  Sorry thought I'd better add that I build individual SQL's for each table with the above string.

Probably not the most exact code, so if you have any better suggestions please let me know.  Also, I did try loading the entire database into an ADO control, but it had all sorts of problems with it.  That is why I ended up moving to the free table access.  Thanks again.

Nemo
0
Comment
Question by:NemoNiente
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 13

Expert Comment

by:Michael_D
ID: 10883448
Try using this;

SELECT * FROM GEN
WHERE FILE_ID IN ( Select FILE_ID FROM FUN)

0
 
LVL 1

Author Comment

by:NemoNiente
ID: 10883630
Thanks for the comment.  Not sure exactly what that does, but it looks like it pulls all the records from the FUN table.  But when I tried it I got this error;

Run-time error '-2147467259 (80004005':
Data provider or other servicer returned an E_Fail status.

It seems to refresh okay, but when I try to access the recordset that is what I get.
0
 
LVL 1

Author Comment

by:NemoNiente
ID: 10896225
Anyone?
0
Technology Partners: 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 11

Expert Comment

by:madgino
ID: 10899121
select distinct GEN.* from gen inner join fun on gen.FILE_ID = fun.FILE_ID

You don't need fun recordset anymore.

If you don't like this you ca change your SQL to look like:

...where FILE_ID in (id1,id2,id3,....)

This will make your sql string smaller.

Your code will be:

MainSqL = "where FILE_ID in ("
FUN.Recordset.MoveFirst
For I = 1 To FUN.Recordset.RecordCount
    If I = FUN.Recordset.RecordCount Then
        MainSqL = MainSqL & "'" & FUN.Recordset.Fields("file_id") & "')"
        Exit For
    Else
        MainSqL = MainSqL & "'" & FUN.Recordset.Fields("file_id") & "',"
End If
    FUN.Recordset.MoveNext
Next
0
 
LVL 13

Accepted Solution

by:
Michael_D earned 2000 total points
ID: 10901479
Sure, you can use this code as well, but if you don't need all records from FUN table you can use WHERE clause of the second SELECT :

SELECT * FROM GEN
WHERE FILE_ID IN ( Select FILE_ID FROM FUN WHERE <Whatever_your_conditions>)


Regarding the error you got:
1) Did you have last service pack installed?
2) How many columns in GEN table (there is limitation of 244 columns)
0
 
LVL 13

Expert Comment

by:Michael_D
ID: 10902576
How did you solve your problem?
0
 
LVL 1

Author Comment

by:NemoNiente
ID: 10906407
SELECT * FROM GEN
WHERE FILE_ID IN ( Select FILE_ID FROM FUN WHERE <Whatever_your_conditions>)

Cleared up my problem with too long of sql statement.  Works like a charm.  Thank you sooo much.
0
 
LVL 13

Expert Comment

by:Michael_D
ID: 10907445
What about run-time error? (-2147467259).
0

Featured Post

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!

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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Suggested Courses

670 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