LPS-37672 Clean up logic in generateSQL.
LPS-37672 SF