Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 16th, 2012  |  syntax: None  |  size: 2.26 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Doing 2 Left Joins on the same table with one call
  2. holdBilling => new
  3. {
  4.       FirstName, LastName, CarrierName, PayerName
  5. }
  6.        
  7. SELECT TOP 1000 [ID]
  8.       ,[bEntityID]
  9.       ,c.carrierID
  10.       ,c.carrierName
  11.       ,p.payerID
  12.       ,p.payerName
  13.       ,[holdType] ( this is "C" for carrier and "P" for payer )
  14.   FROM .[dbo].[holdBilling] hb
  15.   left join dbo.payer p on hb.payerID = p.payerID
  16.   left join dbo.carrier c on hb.carrierID = c.carrierID
  17.   where [bEntityID] = 378
  18.        
  19. var listC = (from hold in holdBilling
  20.               join u in Users on hold.createUserID equals u.userID
  21.               join c in carrier.DefaultIfEmpty() on hold.carrierID equals c.carrierID
  22.                              select new
  23.                              {
  24.                                  Elem = hold,
  25.                                  FName = u.userFirstName,
  26.                                  LName = u.userLastName,
  27.                                  Carrier = c.carrierName,
  28.                                  Payer = ""
  29.                              }).ToList();
  30.        
  31. select new
  32.         {
  33.             Elem = hold,
  34.             FName = u.userFirstName,
  35.             LName = u.userLastName,
  36.             Carrier = "",
  37.             Payer = p.payerName
  38.         }).ToList();
  39.        
  40. var listC = (
  41.                 from hb in holdBilling
  42.                 from p in payer.Where(a=>a.payerID==hb.payerID).DefaultIfEmpty()
  43.                 from c in carrier.Where(a=>a.carrierID=hb.carrierID).DefaultIfEmpty()
  44.                 where hb.bEntityID==378
  45.                 select new
  46.                 {
  47.                     hb.bEntityID,
  48.                     c.carrierID,
  49.                     c.carrierName,
  50.                     p.payerID,
  51.                     p.payerName,
  52.                     holdType=(payer==null?"P":"C")
  53.                 }
  54.                 ).Take(1000)
  55.                 .ToList();
  56.        
  57. var listC = (from hold in holdBilling
  58.               from u in Users.Where(x => hold.createUserID == x.userID).DefaultIfEmpty()
  59.               from c in carrier.Where(x => hold.carrierID == x.carrierID).DefaultIfEmpty()
  60.               select new
  61.               {
  62.                 Elem = hold,
  63.                 FName = u.userFirstName,
  64.                 LName = u.userLastName,
  65.                 Carrier = c.carrierName,
  66.                 Payer = ""
  67.               }).ToList();