Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
String parsing question
Message
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01127937
Message ID:
01127975
Views:
11
This message has been marked as the solution to the initial question of the thread.
Try
cSelect  = "obligor,obligation,unit,name,addr1"
cGroupby = "obligor, obligation"

= ALINES(laGroupBy, cGroupby, 1, [,])
cNewSelect = ""
FOR lnFor = 1 TO ALINES(laSelect, cSelect, 1, [,])
	lcField = laSelect[lnFor]
	IF ASCAN(laGroupBy, lcField, -1,-1,-1,1+2+4) > 0
		cNewSelect = cNewSelect + [, ] + lcField
	ELSE
		cNewSelect = cNewSelect + [, MIN(] + lcField + [) AS ] + lcField
	ENDIF
ENDFOR

cSelect = SUBSTR(cNewSelect,3)
? cSelect
*--------------------------------------

*** or 
cNewSelect = ""
FOR lnFor = 1 TO GETWORDCOUNT(cSelect, [,])
	lcField = ALLTRIM(GETWORDNUM(cSelect, lnFor, [,]))
	IF ASCAN(laGroupBy, lcField, -1,-1,-1,1+2+4) > 0
		cNewSelect = cNewSelect + [, ] + lcField
	ELSE
		cNewSelect = cNewSelect + [, MIN(] + lcField + [) AS ] + lcField
	ENDIF
ENDFOR

cSelect = SUBSTR(cNewSelect,3)
? cSelect
>I am trying to make some of our code compliant with VFP 9.0. The primary update that I am applying is to add a MIN() to every field in the SELECT that is not in the GROUP BY. Our SQL statements are built so I have the text strings, but I am not very proficient at text manipulation.
>
>cSelect='obligor,obligation,unit,name,addr1'
>cGroupby = 'obligor, obligation'
>
>So I would want to change cSelect to
>cSelect='obligor,obligation,MIN(unit),MIN(name),MIN(addr1)'
>
>How is an efficient way to add the MIN() to any cSelect field that is not in the cGroupby?
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform