select g.Custid, g.Grno, g.Name, case when c.Chno = 123 then c.Chno else null end Chno, case when c.Chno = 123 then c.Chdate else null end Chdate from GrfileB g join Challan c on g.Grno = c.Grnowhere g.Custid = 1 order by g.Grno