I noticed that I made a syntax mistake, ordScope should be surrounded with parentheses like this: (cAlias)->(ordScope(0,"T"+cCustno)) (cAlias)->(ordScope(1,"T"+cCustno)) You might also want to consider using database objects which frees you from using aliases ...