0
votes

I have two tables i want to select some specific numbers of records from table 1. the count of records must be equal to value mention in table 2.

Table1
Table 1

Table2
Table 2

Number of records in output must be equal to qty column in table 2. is it possible using access or i have to use VBA.

2

2 Answers

1
votes

You can use a Cartesian (multiplying) query:

SELECT 
    Products.*, 
    Barcodes.*
FROM 
    (SELECT DISTINCT 
        [Tens]+[Ones] AS Factor, 
        10*Abs([Deca].[id] Mod 10) AS Tens, 
        Abs([Uno].[id] Mod 10) AS Ones
    FROM 
        MSysObjects AS Uno, 
        MSysObjects AS Deca) AS F, 
    Products 
INNER JOIN 
    Barcodes
    ON Products.Barcode = Barcodes.Barcode
WHERE 
    F.Factor <= Barcodes.Qty;

This will create up to 100 labels per barcode.

0
votes

"Top N" limits the number of records.

"Select Top 5 Barcode, Brand, Qty FROM Table1 WHERE Barcode = 4044228585563"

Use Union to Select the Top N record from multiple Items

Select Top 5 Barcode, Brand, Qty FROM Table1 WHERE Barcode = 4044228585563
Union
Select Top 5 Barcode, Brand, Qty FROM Table1 WHERE Barcode = 4029045653046