Hi @vsslasd ,
Please have a try with below and check whether it is helpful to you. Thanks.
Select
A.Invoice,
B.PO,
VendorId=
(SELECT TOP 1 VENDORID
FROM Vendors
TABLESAMPLE (1000 ROWS)
WHERE A.Invoice = A.Invoice and B.po=B.po
ORDER BY NEWID())
From APTrans A
Cross Join APTemplate B
OR:
SELECT
A.Invoice,
B.PO,
C.VendorId
FROM APTrans A
CROSS APPLY APTemplate B
CROSS APPLY ( SELECT TOP 1 VendorId
FROM Vendors TABLESAMPLE (1000 ROWS)
WHERE A.Invoice = A.Invoice and B.po=B.po
ORDER BY NEWID()
) C
If the response is helpful, please click "Accept Answer" and upvote it.
Best regards
Melissa