Solved

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

Posted on 2004-04-21
8
409 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
 
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now