Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
GroupBy and Collecting Field Values into a memo field
Message
From
06/04/2005 11:26:20
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 6 SP5
OS:
Windows XP SP2
Network:
Windows NT
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01001575
Message ID:
01001920
Views:
12
>>>No, there is no a direct way to do this (at least I don't know one).
>>
>>remembering that that i've asked that question before {imbaresed smile}, i found the answer from Sergey back then message #875196 .
>>
>>so i have updated my querry to this functionality. but i still would like to have it in a memo field. i think (not too long ago) i saw a solution to add a memo field to a sql command from Sergey, but i don't remember which message it is. as i remember it was a 2 step solution.
>>
>>anyone remembers that thread?
>>
>I do :) Re: Extra memo field in an SQL select Message #706823


hehe, i thought you would <vbg> thank you!

based on your response and the reply's from Borislav and Vladimir i cam up with the following, which works for me. i still could not figure out how to populate a memo field within the sql command (vfp6) - well i just have to live with it.
* *** prepare a cursor to supply a memo field
CREATE CURSOR curTempOeno (Oeno n(8), Item n(6), TempId c(10))
index on TempId tag TempId
set order to TempId
CREATE CURSOR curTempMemo (OERef M)
APPEND BLANK

_TALLY = 0

* *** do the actual querry and collect the data
SELE ;
		COUNT(*) AS ItemCount, ;
		This._CombineOENumbers(q_CoDet.pn,q_CoDet.opt1,q_CoDet.opt2,q_CoDet.opt3,q_CoDet.opt4,q_CoDet.opt5,q_CoDet.opt6,q_CoDet.opt7,q_CoDet.opt8,q_CoMast.duedate) as OERefTemp, ;
		curTempMemo.OERef AS OERef, ;
		q_CoDet.pn, ;
		q_CoDet.opt1, ;
		q_CoDet.opt2, ;
		q_CoDet.opt3, ;
		q_CoDet.opt4, ;
		q_CoDet.opt5, ;
		q_CoDet.opt6, ;
		q_CoDet.opt7, ;
		q_CoDet.opt8, ;
		SUM(q_CoDet.qtyord) AS qtyord, ;
		iif(IsBlank(q_CoDet.duedate), q_CoMast.duedate, q_CoDet.duedate) ;
	FROM ;
		mrp_codet AS q_CoDet inner JOIN mrp_comast AS q_CoMast ON q_CoDet.oeno = q_CoMast.oeno, ;
		curTempMemo ;
	WHERE ;
		&cFilterString ;
	GROUP BY ;
		q_CoDet.pn, ;
		q_CoDet.opt1, ;
		q_CoDet.opt2, ;
		q_CoDet.opt3, ;
		q_CoDet.opt4, ;
		q_CoDet.opt5, ;
		q_CoDet.opt6, ;
		q_CoDet.opt7, ;
		q_CoDet.opt8, ;
		q_CoMast.duedate ;
	INTO CURSOR (OECursor)

* *** remember how many result-records we got
nRecProccessed = _TALLY

* *** in vfp6 we must cheat a bit here
* *** in order to put all oeno's and items in a memo field
* *** we must 1st put the in a seperate table with an id linking
* *** them to the record in the master table
* *** then we have to scan it and add the numbers to the memo field
* *** in vfp9 we can use the Cast() function to convert a returning
* *** character string to a memo string/field
* *** all this is needed for reporting and reference reasons
sele (OECursor)
oToolBox.oLocalSql.MakeCursorReadWrite(OECursor)
scan
	sele curTempOeno
	seek &OECursor..OERefTemp
	scan rest while curTempOeno.TempId == &OECursor..OERefTemp
		repl ;
			&OECursor..OERef with ;
				iif(Empty(&OECursor..OERef), "", &OECursor..OERef+"|") + ;
				trans(curTempOeno.oeno) +","+ ;
				trans(curTempOeno.item)
	endscan
	sele (OECursor)
endscan

* *** ************************************************
Procedure _CombineOENumbers
LPARA ;
	cPn, ;
	cOpt1, ;
	cOpt2, ;
	cOpt3, ;
	cOpt4, ;
	cOpt5, ;
	cOpt6, ;
	cOpt7, ;
	cOpt8, ;
	dDueDate
LOCAL ;
	OldSelect, ;
	a_TempOeReference(1,2), ;
	ReturnedRecords, ;
	i, ;
	ReturnValue

* *** this method will collect all oeno's and item's for the combined
* *** partnumbers (groubBy) in the CollectDataFromOE() Method

OldSelect	= SELECT()
cTempId		= SYS(2015)

SELE ;
		q_temp.oeno, ;
		q_temp.ITEM, ;
		m.cTempId AS TempId ;
	FROM ;
		codet AS q_Temp inner JOIN comast AS q_Temp1 ON q_Temp.oeno = q_Temp1.oeno ;
	WHERE ;
		q_temp.pn = cPn .AND. ;
		q_temp.opt1 = cOpt1 .AND. ;
		q_temp.opt2 = cOpt2 .AND. ;
		q_temp.opt3 = cOpt3 .AND. ;
		q_temp.opt4 = cOpt4 .AND. ;
		q_temp.opt5 = cOpt5 .AND. ;
		q_temp.opt6 = cOpt6 .AND. ;
		q_temp.opt7 = cOpt7 .AND. ;
		q_temp.opt8 = cOpt8 .AND. ;
		q_Temp1.duedate = dDueDate ;
	INTO ;
		ARRAY a_TempOeReference

SELE curTempOeno
APPEND FROM ARRAY a_TempOeReference

SELECT(m.OldSelect)
RETURN(m.cTempId)
EndProc
Thank you all for all your help!
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform