Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Array passing in SQL UDF
Message
 
 
À
09/01/2000 10:56:54
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00314970
Message ID:
00315179
Vues:
1565
Kenneth,

Sorry, if it's not an answer on your original question, but it seems to me that your code needs a little improvement. See my code under yours...

>> Select * from Customer where cust_ID in (SELECT cust_ID from CurSelectedItems).
>> Same approach DF adviced.
>> HTH
>
>Actually that is different from what DF suggests but you get the idea. David's suggestion is what I want to do.
>What I was doing is in the following code:
>
>
Function fSeekpair
>
>** determine if cPerson_id has bought all the items in ItemsArray
>** Purchase table has an index on cPerson_id+cItem_id.     ItemsArray is an array of cItem_id
>
>Parameters cPerson_id, ItemsArray, nArraySize
>
>Local nCnt, lPairFound
>
>nCnt = 1
>lPairFound = .T.
>	
>Do While nCnt <= nArraysize.AND.lPairFound
>	lPairFound=Seek(cPerson_id+aItemsArray[li,1],'PURCHASE','Person_Item') .AND. lPairFound
>	li=li+1
>EndDo
>
>Return lPairFound
Function fSeekpair

** determine if cPerson_id has bought all the items in ItemsArray
** Purchase table has an index on cPerson_id+cItem_id.     ItemsArray is an array of cItem_id

Parameters cPerson_id, ItemsArray

Local lnCnt, llPairFound, lnArraySize

lnArraySize=alen(ItemsArray,1) && assuming two-dimensional array (code, description)

llPairFound = .T.
	
for lnCnt=1 to lnArraySize 
	llPairFound=Seek(cPerson_id+aItemsArray[lnCnt,1],'PURCHASE','Person_Item')
        if not llPairFound && Person hasn't bought this item
           exit && stop at this point
        endif  
endfor

Return lPairFound
>To get all people who bought the n items in aItemsArray
>
>
Select cPerson_id from PERSONS where fseekpair(cPerson_id,@Itemlist,Itemlistnumber) ;
>                into cursor something

>I will try David's approach since it does look much cleaner but I'm still trying to figure out

I would suggest to try my approach first (using subquery), because you don't need to get additional info about Items, right? If you need to select cPerson_Id only, do it the simplest way: use subQuery.

If you take a look into SQL help, you'd find, that UDF is not a good place for SQL.

>1) Why does this function work when called directly but loses it in the SQL Select

See SQL Help.

>2) Why is this a bad way to do this? What problems can it cause (ED).
>
>Thanks everyone for all the help
If it's not broken, fix it until it is.


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

Click here to load this message in the networking platform