CREATE VIEW "SBODEMODE"."OSRI" ( "ItemCode", "SysSerial", "SuppSerial", "IntrSerial", "BatchId", "ExpDate", "PrdDate", "InDate", "GrntStart", "GrntExp", "WhsCode", "Located", "Notes", "Quantity", "BaseType", "BaseEntry", "BaseNum", "BaseLinNum", "CreateDate", "CardCode", "CardName", "ItemName", "Status", "Direction", "DataSource", "UserSign", "Transfered", "Instance" ) AS SELECT "T11"."ItemCode" , "T11"."SysSerial" , "T11"."SuppSerial" , "T11"."IntrSerial" , "T11"."BatchId" , "T11"."ExpDate" , "T11"."PrdDate" , "T11"."InDate" , "T11"."GrntStart" , "T11"."GrntExp" , "T11"."WhsCode" , "T11"."Located" , "T11"."Notes" , "T11"."Quantity" , "T11"."BaseType" , "T11"."BaseEntry" , "T11"."BaseNum" , "T11"."BaseLinNum" , "T11"."CreateDate" , "T11"."CardCode" , "T11"."CardName" , "T11"."ItemName" , "T11"."Status" , "T11"."Direction" , "T11"."DataSource" , "T11"."UserSign" , "T11"."Transfered" , "T11"."Instance" from (SELECT T0."ItemCode" AS "ItemCode",T0."SysNumber" AS "SysSerial",T0."MnfSerial" AS "SuppSerial",T0."DistNumber" AS "IntrSerial",T0."LotNumber" AS "BatchId",T0."ExpDate" AS "ExpDate",T0."MnfDate" AS "PrdDate",T0."InDate" AS "InDate",T0."GrntStart" AS "GrntStart",T0."GrntExp" AS "GrntExp",OSRQ."WhsCode" AS "WhsCode",T0."Location" AS "Located",T0."Notes" AS "Notes",T2."DocQty" AS "Quantity",T2."DocType" AS "BaseType",T2."DocEntry" AS "BaseEntry",T2."DocNum" AS "BaseNum",T2."DocLine" AS "BaseLinNum",T0."CreateDate" AS "CreateDate",( CASE when T2."DocType" = 59 or T2."DocType" = 60 or T2."DocType" = 10000071 or T2."DocType" = 310000001 or T2."DocType" = 58 then NULL ELSE T2."CardCode" END ) AS "CardCode",( CASE when T2."DocType" = 59 or T2."DocType" = 60 or T2."DocType" = 10000071 or T2."DocType" = 310000001 or T2."DocType" = 58 then NULL ELSE T2."CardName" END ) AS "CardName",T2."ItemName" AS "ItemName",(case when OSRQ."Quantity" is null then 1 when OSRQ."Quantity" = 0 then 1 when OSRQ."Quantity" = 1 then 0 else null end) AS "Status",0 AS "Direction",T0."DataSource" AS "DataSource",T0."UserSign" AS "UserSign",T0."Transfered" AS "Transfered",T0."Instance" AS "Instance" FROM "SBODEMODE".OSRN T0  LEFT JOIN "SBODEMODE".OSRQ OSRQ  ON T0."ItemCode" = OSRQ."ItemCode" AND T0."SysNumber" = OSRQ."SysNumber"  INNER JOIN "SBODEMODE"."ixvITL_Min" T1  ON T0."ItemCode" = T1."ItemCode" AND T0."SysNumber" = T1."SysNumber"  INNER JOIN "SBODEMODE".OITL T2  ON T2."LogEntry" = T1."LogEntry" AND T2."ItemCode" = T1."ItemCode"  WHERE (OSRQ."Quantity" is null OR OSRQ."Quantity" = 0 or OSRQ."Quantity" = 1)  ) t11  INNER JOIN "SBODEMODE"."ixvITL_LastWhs" T3  ON T11."ItemCode" = T3."ItemCode" AND T11."SysSerial" = T3."SysNumber"   AND t11."WhsCode" = T3."WhsCode" WITH READ ONLY