Monday, October 8, 2007

Case Insensitive sorting in SQL/400:

In SQL, the default sort sequence is done by the Hexadecimal value of the characters. As a result of this when character sorting is performed, lower case letter are sorted first followed by the upper case characters. This results in irregular or undesirable results. Following is the solution available to avoid this problem.
In interactive SQL, press the F13 key and select option 1 ("change session defaults"). Page down once and change the sort sequence entry to *LANGIDSHR.
For programs that include embedded SQL, we have two choices. One method is to change the SRTSEQ parameter of the command that is used to create the program (for example, CRTSQLRPGI). The better solution is to code a SET OPTION command in the source code, as the following RPG snippet illustrates.
C/exec sql
C+ set option srtseq=*langidshr
C/end-exec

This set up process sorts the record based on the character in the language and not by its hex values.

No comments: