Solved

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

Posted on 2004-04-21
8
439 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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
Course of the Month5 days, 4 hours left to enroll

636 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