Select Distinct S1.Etyno,S1.Etydate,S1.party,S1.GpNo,S1.GPDATE,S1.InvNo,Isnull(S1.InvDate,'01-Jan-1899') InvDate,S2.ITEM,S2.Qty,S1.DcNo,Isnull(S1.DcDate,'01-Jan-1899') DcDate, G1.GRNNO , S4.DIVISION , S1.WGRN  ,S1.through , S1.Parcel_Amount ,G1.GPNO Grn_GPNo, G1.GPDATE Grn_GpDate ,  S1.remarks , S1.sec1 , S1.Division_Code ,    S1.Bus_Parcel_Mode , S1.Fabric, S1.WoPO, isnull(S22.Supplier_Code,0) Partycode  From Sec_trn_inwardmas S1 Left join Sec_trn_inwardDet S2 on S1.EtyNo = S2.EtyNo LEft Join Inward_Against_PO_Tbl S22 On S1.EtyNO = S22.Inw_Eno  Left Join GrnMaster G1 on cast(S1.Division_Code as varchar (2)) = cast(G1.Division_Code as varchar (2)) And cast(S1.GPNo as varchar (50)) = cast(G1.GPNO as varchar (50)) and S1.GpDate = G1.GpDate Left join Sec_Division() S4 on S1.Division_Code = S4.Nos Left join FITSOCKS.dbo.Socks_Gate_Pass_GrnNo_Fn() SG On S1.GPNo= SG.GPNO And S1.GPDATE = SG.GPDATE And S1.PARTY = SG.PARTY Left join EXIM.dbo.Export_MaterialInward_Link_Details E1 On S1.Etyno = E1.Inward_Etyno Left join FITERP1314.dbo.Pur_Grn_Mas F1 On S1.Gpno=F1.GateInwId And S1.GpDate=F1.GateInWDate And 5=S1.Division_Code Left join FITERP1314.dbo.Prod_Recpt_MAs F2 On S1.Gpno=F2.GateInwId And S1.GpDate=F2.GateInWDate And 5=S1.Division_Code Left join OFFSET_PRINTING.dbo.Pur_Grn_Mas F3 On S1.Gpno=F3.GateInwId And S1.GpDate=F3.GateInWDate And 3=S1.Division_Code Left join GAR_PRINT.dbo.Pur_Grn_Mas F4 On S1.Gpno=F4.GateInwId And S1.GpDate=F4.GateInWDate And 2=S1.Division_Code Left join GAR_PRINT.dbo.Pur_Grn_Mas F5 On S1.Gpno=F5.GateInwId And S1.GpDate=F5.GateInWDate And 8=S1.Division_Code Left join LOTMASTER F6 On S1.Gpno=F6.Gpno And S1.GpDate=F6.GpDate And S1.Division_Code=F6.Sec_division Left join Vehicle_Travell_Expense_Master F7 On F7.InWard_EntryNo = S1.Etyno Where  F7.InWard_EntryNo Is Null And Cast(S1.Etydate As Date) >=DateAdd(YEAR,-1,Cast(GETDATE() As Date)) And Cancel_Flag = 0 And G1.GRNDATE Is Null And G1.GRNNO Is Null And E1.Inward_Etyno Is NUll And F6.Gpno Is null And F6.GpDate Is null And (SG.GPNo Is Null Or SG.GPDate is Null Or SG.InvNo Is Null Or SG.InvDate Is NUll) And (F1.GateInwId Is Null And F1.GateInWDate Is null) And (F2.GateInwId Is Null And F2.GateInWDate Is null)  And (F3.GateInwId Is Null And F3.GateInWDate Is null) And (F4.GateInwId Is Null And F4.GateInWDate Is null) And (F5.GateInwId Is Null And F5.GateInWDate Is null)   And S4.Nos in(11,12,16)




