0

I would appreciate it if someone can explain me how the piece of code below works internally. For example, how the order of conditions is evaluated.

 update br set ScannedId =
    (
    select top 1 Id from table1 sp (nolock)
     inner loop join table2 cp  (nolock) ON (sp.CPId = cp.CPID) 
     inner loop join table3 c  (nolock) ON (cp.CID = c.CId and c.endDate >= sp.CreatedDate and c.startDate <= sp.CreatedDate ) `enter code here`
     inner loop join table4 cc  (nolock) ON (c.CChannelID =`enter code here` cc.CChannelID)
     where (sp.UserId is null or sp.UserId = br.UserId) 
           and ((sp.Email = br.UserEmail)             
               or (sp.fName like br.UFName + '%' and sp.LName like br.ULName + '%' and sp.sHash = br.uHash)
               or (sp.fName like br.UFName + '%' and sp.Addrs = br.UOAddrs and sp.ZC = br.UOZ and sp.sHash = br.uHash))
       order by  cc.Rank, c.Rank, cp.Rank, sp.EDate desc, sp.CreatedDate desc
    )
    from channelnewlogic br where userId = 3637217
Tim Visée
  • 2,988
  • 4
  • 45
  • 55
  • possible dupe https://stackoverflow.com/questions/30749913/which-performs-first-where-clause-or-join-clause – gordy Aug 03 '17 at 02:19

1 Answers1

0

Rows in channelnewlogic get their ScannedId column values updated according to the result of the inner select.

SAS
  • 3,943
  • 2
  • 27
  • 48