in reply to SQL Problem. Perl solution?
What database is this? Why does the solution need to moved from sql to (perl) code?
The table name of #tmp_G_P_M_CC_S_S immediately jumps out at me -- that should probably be quoted as "#tmp_G_P_M_CC_S_S" and could quite possibly be the problem...