-
MelissaMa-MSFT 24,126 Reputation points Microsoft Employee
2020-09-04T02:01:43.047+00:00 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
Have you tried removing the TABLESAMPLE clause? I don't have much faith in that one.