Hello,
I am trying to bring the “UserName” field from Query 2 to all applicable records in Query 1 based on Query1.[DateSeq]=Query2.KeyString and Query1.[ViewName]=Query2.ViewName ( I can only join Query1 to Query2 using the calculated fields ( [DateSeq] and ViewName]) as those fields do not exist in any other views except Query2)
Query 1:
SELECT i.APCo AS APCompany, i.UIMth AS APUIUIMth, i.UISeq AS APUIUISeq, l.Line AS APULLine, i.Vendor AS APUIVendor, i.APRef AS APUIAPRef, i.Description AS APUIDesc, i.InvTotal AS APUIInvTotal, r.Reviewer AS APURReviewer, v.Name AS APVMName, e.RevEmail AS HQRVRevMail, e.Name AS HQRVName, l.Description AS APULDesc, l.GrossAmt AS APULGrossAmt, r.DateAssigned, Concat('UIMth:',' ', Convert(varchar(10), i.UIMth,1),' ', 'UISeq:',' ', i.UISeq ) as [DateSeq], 'APUI' as [ViewName], brvHQAuditDetail.UserName
Query 2
Select * from brvHQAuditDetail where ViewName='APUI' and RecType='A'
So far I tried the following but it does not work
SELECT i.APCo AS APCompany, i.UIMth AS APUIUIMth, i.UISeq AS APUIUISeq, r.DateAssigned, Concat('UIMth:',' ', Convert(varchar(10), i.UIMth,1),' ', 'UISeq:',' ', i.UISeq ) as [DateSeq], 'APUI' as [ViewName], brvHQAuditDetail
FROM bAPUI AS i WITH (Nolock) INNER JOIN
bAPUL AS l WITH (Nolock) ON i.APCo = l.APCo AND i.UIMth = l.UIMth AND i.UISeq = l.UISeq INNER JOIN
bAPUR AS r WITH (Nolock) ON l.APCo = r.APCo AND l.UIMth = r.UIMth AND l.UISeq = r.UISeq AND l.Line = r.Line INNER JOIN
bAPVM AS v WITH (Nolock) ON i.VendorGroup = v.VendorGroup AND i.Vendor = v.Vendor INNER JOIN
bHQRV AS e WITH (Nolock) ON r.Reviewer = e.Reviewer
Inner join brvHQAuditDetail AS p WITH (Nolock) On Concat('UIMth:',' ', Convert(varchar(10), i.UIMth,1),' ', 'UISeq:',' ', i.UISeq )=p.KeyString And [ViewName] =p.ViewName
It is giving me an error when I run it - Invalid column name 'brvHQAuditDetail'.
Do you have any idea on how to fix it?
Thanks in advance