Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL Expression is too complex
Message
 
 
À
17/05/2001 09:18:49
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00508252
Message ID:
00508277
Vues:
20
This message has been marked as a message which has helped to the initial question of the thread.
Michael,

You can use several INLIST combained with OR clause. Or you can create a cursor of all codes and then just use select * from myTable where code in (select code from myCursor).

This is how I implemented this criterion: (I used temporary table approach, but I probably have to re-think it):
********************************************************************
*  Description.......: BTCC_group.BTC_WherExp: obtain the search expression for this criterion
*  Calling Samples...:
*  Parameter List....: mapto_arg
*  Created by........:
*  Modified by.......: Nadya Nosonovsky 09/29/2000 03:21:53 PM
********************************************************************
* This function returns a single piece of the search criteria, or empty string if nothing selected.
lparameters mapto_arg, tcQueryType, tnMaxLen, tnNumCrit, tlShowCrit
* takes 5 optional arguments
* mapto_arg:                         optional alias.fieldname mapping to use in resulting expression.
*                                        If omitted or empty, the mapping is determined by the array
*                                        property, btcmaparray, for the current query type.
local lcCrit, lcRetValue, lnSel, i, lnCodes, mapto
if vartype(m.gcTempPath)<>"C" && Variable is not yet defined
     public gcTempPath
     gcTempPath=addbs(sys(2023))
endif
with this
     mapto=iif(empty(m.mapto_arg), .btcMapArray[thisform.btcQTmappingNum], m.mapto_arg)
     if empty(m.mapto) && empty for this Query Type && or control is not visible
          lcRetValue=''
          return m.lcRetValue
     endif
     lcCrit = .BTC_ItemList()          && get the list of selected items
     if empty(m.lcCrit)                    && no explicit selection was made
          lcRetValue=''                    && null criterion result
     else
          lnCodes=.nSelects
          if empty(m.lnCodes)
               lnCodes=occurs(',',m.lcCrit)+1 && Number of commas within crit
          endif
          do case
          case m.lnCodes=1 && only one value
               lcRetValue= m.mapto+iif(.ExcludeFlag,'<>','=') + m.lcCrit
          case m.lnCodes<=24 and m.lnCodes < .nMaxSelects && INLIST function is limited by 24 codes
* return INLIST() criterion for field value in an enumerated list
               lcRetValue=  iif(.ExcludeFlag,'!','')+'INLIST(' + m.mapto + ',' + m.lcCrit + ')'
          case m.lnCodes>24 and m.lnCodes< .nMaxSelects
* Temproraly solution - breaks on the several INLISTs
               lcCrit=''
               lcRetValue=''
               for i=1 to m.lnCodes
                    lcCrit=m.lcCrit+'"'+.btcSelArray[i]+'"'+iif(mod(m.i,24)=0 or m.i=m.lnCodes,'',',')
                    if mod(m.i,24)=0
                         lcRetValue=m.lcRetValue + ;
                              iif(m.i>24,iif(.ExcludeFlag,' and not',' or'),iif(.ExcludeFlag,'not','')) + ;
                              ' INLIST(' + m.mapto + ',' + m.lcCrit + ')'
                         lcCrit=''  && Start a new loop
                    endif
               next
               if !empty(m.lcCrit)          && Remainder
                    lcRetValue=m.lcRetValue + iif(.ExcludeFlag,' and not',' or') + ;
                         ' INLIST(' + m.mapto + ',' + m.lcCrit + ')'
               endif
               lcRetValue='('+alltrim(m.lcRetValue)+')' && Surrounded by ()
          case m.lnCodes >= .nMaxSelects
               local lcTempName
               lcTempName='btc'+proper(substr(m.mapto,rat('.',m.mapto)+1))
               .btcJoinExp=' INNER JOIN ' + m.gcTempPath + .TableName+' ' + ;
                    m.lcTempName+' ON '+ m.mapto + '='+m.lcTempName+'.BtcCode'
               lcRetValue=m.mapto + iif(.ExcludeFlag,' NOT','') + ;
                    ' IN ('+m.lcCrit+')'
               if m.tlShowCrit
                    tnMaxLen=max(m.tnMaxLen,len(m.lcCrit)) && Calculate max length
                    tnNumCrit=m.tnNumCrit+round(len(m.lcCrit)/100,0)+1 && Increment number of strings
               endif
          endcase
     endif
endwith
return m.lcRetValue
>Hi All,
>
>I am trying to create a screen where the user can select criteria for a report. The problem I am running into is that when I use the 'IN ()' in the WHERE clause there is a limit of 25 items per 'IN'. I might need up to 100+ in some cases. I need to have from 1 to 13 possible 'IN's in the statement. Since we are using the VFP ODBC to access a standard 'DBC' type database. The notion of Stored Proc is out of the question from what I've been told. If the criteria is kept to a minimum everything works fine. But this may not always be the case.
>
>Anybody have an idea of a way to get around this limitation? Will I have to do several queries? If so, at what level do I do the breakdown?
>
>TIA
>Mike
>
>P.S. VFP6 SP3
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform