Solved

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

Posted on 2004-04-21
8
416 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA color chart bars 12 77
Access 2013 combo box not working 3 38
How does CurrentUser work? 10 31
Search combo error "Data Type Mismatch in Criteria Expression" 2 51
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…

919 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

22 Experts available now in Live!

Get 1:1 Help Now