create or replace view v_rejectedscansperworkstation as
select rs.transactiontype_id,
       coalesce((select transactiontype_desc.description
                   from transactiontype_desc
                  where transactiontype_desc.transactiontype_id =
                        rs.transactiontype_id
                    and transactiontype_desc.language_id =
                        languages.language_id), tt.factorydescription) transactiontypedesc,
       coalesce(rs.scanstation, ' ') workstationcode,
       (select w.description
           from workstation w
          where w.code = rs.scanstation) workstationdesc, sy.username,
       sy.fullname, rs.scantimestamp scandate,
       gettimeasnumeric(rs.scantimestamp) scantime_number,
       bu.code businessunitcode, bu.businessunit_id,
       bu.description businessunitdesc, mre.multireadexceptionreason_id,
       coalesce((select mred.description
                   from multireadexceptionreason_desc mred
                  where mre.multireadexceptionreason_id = mred.multireadexceptionreason_id
                    and mred.language_id = languages.language_id), mre.factorydescription) reason_code,
       languages.code languagecode, bug.usergroup_id, rs.rejectedscan_id
  from rejectedscan rs
  join businessunit bu on rs.businessunit_id = bu.businessunit_id
  join businessunitsperusergroup bug on bu.businessunit_id = bug.businessunit_id
  join systemuser sy on rs.systemuser_id = sy.systemuser_id
  join transactiontype tt on rs.transactiontype_id = tt.transactiontype_id
  join multireadexceptionreason mre on rs.multireadexceptionreason_id = mre.multireadexceptionreason_id
 cross join languages
/
