Solved

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

Posted on 2004-04-21
8
425 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
  • 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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 500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

856 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