Microsoft Access query returning sequential numbers

前端 未结 2 1352
我在风中等你
我在风中等你 2021-01-21 16:49

Is there any way to create query in MS Access which returns sequential numbers of my choice? For example

10.1
10.2
10.3
10.4
10.5

or



        
2条回答
  •  孤街浪徒
    2021-01-21 17:45

    I think you can use a solution like this:

    1. Make a table (name it t) like this:

      ID | i
      ---+---
      1  | 0
      2  | 1
      3  | 2
      4  | 3
      5  | 4
      6  | 5
      7  | 6
      8  | 7
      9  | 8
      10 | 9
      
    2. Now use this table for all you need, for example make a query from 0 to 9999 use this query:

      SELECT 
          i1 + i2 * 10 + i3 * 100 + i4 * 1000 AS rowNo
      FROM 
          (SELECT 
              t1.i AS i1, t2.i AS i2 
           FROM 
              t AS t1, t AS t2) AS tt1, 
          (SELECT 
              t1.i AS i3, t2.i AS i4 
           FROM 
              t AS t1, t AS t2) AS tt2;
      
    3. For example you can change rowNo formula to these:

      CDbl('10.'+CStr([i1]+[i2]*10+[i3]*100+[i4]*1000))   =>  10.1, 10.2, ...
      

      or

      (10000 - ([i1]+[i2]*10+[i3]*100+[i4]*1000)) * 10    => 100000, 99990, ... , 20, 10
      

      or

      DateAdd("h",[i1]+[i2]*10+[i3]*100+[i4]*1000,#4/10/2015 12:00:00 PM#)
      

提交回复
热议问题