Repeat records according to a quantity field

前端 未结 2 834
南方客
南方客 2020-12-17 07:02

I have an Excel sheet which I receive from my customer and I get imported to Access and I would call that table [tblCustomer] and that would look something like this:

<
2条回答
  •  自闭症患者
    2020-12-17 07:28

    Here's the solution using Erik von Asmuth's comment which pointed to an answer originally created by Gustav.

    SELECT t.*
    FROM tblCustomer AS t
    INNER JOIN (SELECT DISTINCT 
                [Hundreds]+[Tens]+[Ones] AS Factor, 
                100*Abs(Hundo.id Mod 10) AS Hundreds,
                10*Abs(Deca.id Mod 10) AS Tens, 
                Abs(Uno.id Mod 10) AS Ones
            FROM 
                msysobjects AS Uno, 
                msysobjects AS Deca,
                msysobjects As Hundo
            WHERE Abs(Deca.id Mod 10) <> 0 
                    or Abs(Uno.id Mod 10) <> 0
                    or Abs(Hundo.id Mod 10) <> 0) AS sq on sq.Factor <= t.SumofQty
    

    I added the hundreds column as well because I think I'm probably going to need it. My method also filters out 0 in the sub query, otherwise I was getting 2 rows for things with a quantity of 1.

提交回复
热议问题