>Part No Recseq
>854411-401 0000001
>854411-402 0000002
>854411-403 0000003
>854411-405 0000004
>854411-405 0000005
>854411-405 0000006
>854411-407 0000007
>
>My desired string:>CLEAR >SET EXACT On >partnoS = "" >partnoS2 = "" >recseqS2 = "" >openP = "" >closeP = "" > >SELECT testQuery >SCAN > > IF AT(ALLTRIM(testQuery.partno), partnoS2) < 1 Then > > partnoS = ALLTRIM(partno)+"(" > closeP = ")," > ELSE > partnoS = "" > closeP = "," > ENDIF > partnoS2 = partnoS2 + ALLTRIM(partno) > recseqS2 = recseqS2 + partnoS + recseq + closeP >ENDSCAN > >? recseqS2The general principle is to hold the current part in the variable. Once you found that your variable is not equal to the current part you may do your closing code and update the variable.