$CaseId=$_SESSION[`CaseId`];
$UserId=$_SESSION[`UserId`];

$Instance=ShowQueryResultScalar(~select rUnique from Responses where CaseID=`$CaseId` and rInstance=`Expense`~);

if ($Instance==~~)
   {
      ExecuteSQL(~insert into Responses (CaseID,qID,uID,rInstance,ProjectId) select `$CaseId`,`RE_X_Category`,`$UserId`,`Expense`,`~.$_SESSION[`ProjectId`].~`~);
      $Instance=ShowQueryResultScalar(~select rUnique from Responses where CaseID=`$CaseId` and rInstance=`Expense`~);
      ExecuteSQL(~update Responses set rInstance=`$Instance` where rUnique=`$Instance`~);
   }
$_SESSION[`Instance`]=$Instance;
SetForm(`Transaction_Detail`);

$stat=1;