sql - Combining two select statements -


i have 2 statements such:

var chgassociationquery1 = (from in sostenuto.problems   join b in sostenuto.s_association on a.servicereqno equals b.fromservicereqno   join c in sostenuto.changes on b.toservicereqno equals c.servicereqno   b.fromserviceid == 101001110      && b.toserviceid == 101001109      && a.name.contains(name)   select new { problemreqno = a.servicereqno,                   problemid = a.servicereqid,                  changereqno = c.servicereqno,                     changeid = c.servicereqid,                changenumber = c.csebranchchange,                changebranch = c.maintbranch});  var chgassociationquery2 = (from in sostenuto.problems   join b in sostenuto.s_association on a.servicereqno equals b.toservicereqno   join c in sostenuto.changes on b.fromservicereqno equals c.servicereqno   b.fromserviceid == 101001109      && b.toserviceid == 101001110      && a.name.contains(name)   select new { problemreqno = a.servicereqno,                   problemid = a.servicereqid,                 changereqno = c.servicereqno,                    changeid = c.servicereqid,                changenumber = c.csebranchchange,                changebranch = c.maintbranch });  var vproblemxchange = chgassociationquery1.union(from in chgassociationquery2 select a); 

and i'm wanting able combine them one; loops through database twice - inefficient. i've tried researching how put multiple select statements within clause can't seem find can understand.

can shed light on situation?

i tried modifying answer below:

        var vproblemxchange =       (from in sostenuto.problems        join b in sostenuto.s_association on a.servicereqno equals b.fromservicereqno        join c in sostenuto.changes on b.toservicereqno equals c.servicereqno        join z in sostenuto.s_association on a.servicereqno equals z.toservicereqno        join y in sostenuto.changes on z.fromservicereqno equals y.servicereqno        ((b.fromserviceid == 101001110 && b.toserviceid == 101001109 && a.name.contains(name)) ||               (z.fromserviceid == 101001109 && z.toserviceid == 101001110) && a.name.contains(name))           && a.name.contains(name)        select new        {            problemreqno = a.servicereqno,            problemid = a.servicereqid,            changereqno = c.servicereqno,            changeid = c.servicereqid,            changenumber = c.csebranchchange,            changebranch = c.maintbranch        }); 

however i'm trying access different joins based on clause, can't change in select statement; example, if second half of or true, should use , y in select rather , c.

try this

var chgassociationquery1 = ((from in sostenuto.problems                                          join b in sostenuto.s_association on a.servicereqno equals b.fromservicereqno                                          join c in sostenuto.changes on b.toservicereqno equals c.servicereqno                                          b.fromserviceid == 101001110                                                && b.toserviceid == 101001109                                                && a.name.contains(name)                                          select new { problemreqno = a.servicereqno, problemid = a.servicereqid, changereqno = c.servicereqno, changeid = c.servicereqid, changenumber = c.csebranchchange, changebranch = c.maintbranch})                                        .union(from in sostenuto.problems                                          join b in sostenuto.s_association on a.servicereqno equals b.toservicereqno                                          join c in sostenuto.changes on b.fromservicereqno equals c.servicereqno                                          b.fromserviceid == 101001109                                                && b.toserviceid == 101001110                                                && a.name.contains(name)                                             select new { problemreqno = a.servicereqno, problemid = a.servicereqid, changereqno = c.servicereqno, changeid = c.servicereqid, changenumber = c.csebranchchange, changebranch = c.maintbranch })).tolist(); 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -