Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Building a SQL statement on the fly
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00263324
Message ID:
00263579
Vues:
24
FWIW, William, this code looks exactly like what I came up with for the same problem, except your variables are different. Great minds...... < grin >

Barbara

>It would never (I know, never say never) exceed 254 fields, but the macro substituted variable containing the field list does on occasion exceed 254. What I did was create an array of 10 elements. As I go to add to the string that is macro expanded, I check to see if it will exceed the 254 limit. If it does, I go to the next element in the array and start adding to it. Then in my SQL statement, I macro expand each element. The elements that don't have any value expand to '' since I initialize them that way. I just thought it was kludgy, but it seems the only way given the limitation of a len of a command executed with Macro substitution.
>
>FWIW, the code is as follows:
>
>DIMENSION laFldStmnt(10)
>laFldStmnt(1) = ''
>laFldStmnt(2) = ''
>laFldStmnt(3) = ''
>laFldStmnt(4) = ''
>laFldStmnt(5) = ''
>laFldStmnt(6) = ''
>laFldStmnt(7) = ''
>laFldStmnt(8) = ''
>laFldStmnt(9) = ''
>laFldStmnt(10) = ''
>lnFldStmnt = 1
>
>SCAN
> lcFldStmnt = ALLTRIM(Field_Name) + " AS " + ALLTRIM(Master_fld) + ", "
> IF LEN(laFldStmnt(lnFldStmnt)) + LEN(laFldStmnt(lnFldStmnt)) > 254
> * Too big, go to the next item in the array
> lnFldStmnt = lnFldStmnt + 1
> ENDIF
> laFldStmnt(lnFldStmnt) = laFldStmnt(lnFldStmnt) + lcFldStmnt
>ENDSCAN
>
>* Trim the , off the end of the last statement
>laFldStmnt(lnFldStmnt) = LEFT(laFldStmnt(lnFldStmnt), LEN(laFldStmnt(lnFldStmnt)) - 2)
>lcFrom = ALLTRIM(This.cSource)
>lcInto = ALLTRIM(This.cResults)
>
>SELECT ;
> &laFldStmnt(1) ;
> &laFldStmnt(2) ;
> &laFldStmnt(3) ;
> &laFldStmnt(4) ;
> &laFldStmnt(5) ;
> &laFldStmnt(6) ;
> &laFldStmnt(7) ;
> &laFldStmnt(8) ;
> &laFldStmnt(9) ;
> &laFldStmnt(10) ;
> FROM &lcFrom ;
> &lcWhere ;
> INTO CURSOR &lcInto
>
>I just thought it looked sloppy to me.
Barbara Paltiel, Paltiel Inc.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform