Hi Guys,

What the code below does is look for entries from the TBLGRN and TBLUPGRN tables in the TBLINV tables and produces the results for the matching entries with the invoiceno on the datagrid wherever there is a matching value in the voucherno column in both the TBLGRN and TBLUPGRN tables it leaves out those entries in the TBLGRN & TBLUPGRN tables that do not have any values in the voucherno column.

The code works perfectly, but i would like the datagrid to show the entries in the TBLGRN and TBLUPGRN tables which do not also contain any values in the vouvherno column.

For clarification,
TBLGRN & TBLUPGRN and Goods Receivable Tables, while TBLINV is a sales table.

The voucherno column in the TBLGRN & TBLUPGRN table is for the corresponding InvoiceNo column in the TBLINV table.
But its not a must every voucherno should have a corresponding invoiceno value.

Code:
sqlGRN = "select g.ProductID,g.PartNo,g.Description,g.Brand,g.Qty as GRNQTY,i.qty as InvQty,g.VoucherNo,g.GrnDate," & _
         "i.CustomerName,g.CostPrice,i.ItemPrice as SellPrice,(i.itemprice-g.costprice) as DIFF,((i.itemprice/(g.costprice)*100)-100) as Per,'1' as VTYPE from" & _
         " tblupgrn g left join tblinv i on g.voucherno=i.invoiceno where supplier='" & IgridCustomers.cellValue(IgridCustomers.CurRow, "Customer") & "' and" & _
         " i.productid=g.productid group by g.grndate,g.productid,g.partno," & _
         "g.description,g.brand,g.qty,g.costprice,g.voucherno,I.CUSTOMERNAME,I.ITEMPRICE,i.qty union all" & _
        " select g2.ProductID,g2.PartNo,g2.Description,g2.Brand,g2.Qty as GRNQTY,i2.qty as InvQty,g2.VoucherNo," & _
        "g2.GrnDate,i2.customername,(g2.CostPrice/1.18) as CostPrice,i2.itemprice as SellPrice,(i2.itemprice-(g2.costprice/1.18)) as DIFF,((i2.itemprice/(g2.costprice/1.18)*100)-100) as Per,'2' as VTYPE" & _
        " from tblgrn g2 left join tblinv i2 on g2.voucherno=i2.invoiceno where supplier='" & IgridCustomers.cellValue(IgridCustomers.CurRow, "Customer") & "' and" & _
        " i2.productid=g2.productid group by g2.grndate,g2.productid,g2.partno," & _
        "g2.description,g2.brand,g2.qty,g2.costprice,g2.voucherno,I2.CUSTOMERNAME,I2.ITEMPRICE,i2.qty"