Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How long can a SELECT statement be?
Message
From
20/07/2005 17:02:06
 
 
To
20/07/2005 16:40:50
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 7 SP1
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01034427
Message ID:
01034442
Views:
23
>I have a very long SELECT statement that uses a bunch of unions to create a table. I know that there is a limit to how many unions I can have, but is there a limit to how long the actual command can be? I seem to have passed it.

In VFP7 maximum # of characters per command line is 8,192. If you're hitting this limit I can think of a couple of approaches:

1. If you're using table names in your column select clauses, using short table aliases might shorten the whole statement enough to let it work:
* Instead of:
SELECT
  SomeTable.SomeField,
  SomeOtherTable.SomeOtherField
  FROM SomeTable, SomeOtherTable
  ...

* you could use:
SELECT
  A.SomeField,
  B.SomeOtherField
  FROM SomeTable A, SomeOtherTable B
  ...
2. Instead of a massive UNION, you could do separate SELECTs and combine them manually yourself e.g.
* First SELECT:
SELECT ...
  INTO CURSOR Temp1 READWRITE

* Second SELECT:
SELECT ...
  INTO CURSOR Temp2 NOFILTER

SELECT Temp1
APPEND FROM (DBF("Temp2"))
USE IN Temp2

* Repeat for other SELECTS

* Finally, if you have a global GROUP BY, ORDER BY etc.:
SELECT
  *
  FROM Temp1
  GROUP BY ...
  ORDER BY ...
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Reply
Map
View

Click here to load this message in the networking platform