I've fixed these, and my primitive testing indicates it kinda works, at least...
Try it out some more and see what happens. Here's the new
select without the "decode":
set exists_p [database_to_tcl_string $db "select case count(*) when 0 then 0 else 1 end
from ad_partner_procs
where url_id='$QQurl_id'
and proc_name='$QQproc_name'
and proc_id<>$proc_id
and proc_type='$QQproc_type'"]