    select A.ID, 
           GS_COM_ANK_AV('XOSEN_RI', A.ID, :D$DD) as XOSEN_RI_NEW,
           GS_COM_ANK_AV('XOSEN_RI', A.ID, :D$DD-1) as XOSEN_RI_OLD,
           GS_COM_ANK_AV('XOSEN_RA', A.ID, :D$DD) as XOSEN_RA_NEW,
           GS_COM_ANK_AV('XOSEN_RA', A.ID, :D$DD-1) as XOSEN_RA_OLD,
           GS_COM_ANK_AV('XOSEN_RB', A.ID, :D$DD) as XOSEN_RB_NEW,
           GS_COM_ANK_AV('XOSEN_RB', A.ID, :D$DD-1) as XOSEN_RB_OLD,
           GS_COM_ANK_AV('XOSEN_RC', A.ID, :D$DD) as XOSEN_RC_NEW,
           GS_COM_ANK_AV('XOSEN_RC', A.ID, :D$DD-1) as XOSEN_RC_OLD
      from COM_ANKETA A where A.S_S=1 and A.ID in (select VNESHID from COM_ANK_AV where ATT='XOSEN_RI' and trim(VAL_STR) is not NULL)
