PARTITION

PARTITION(number, start, stop, interval)

Returns a string indicating which particular range it falls into (String).


numberThe number you want to evaluate in the range (Long).
startThe start of the range of numbers (Long)
stopThe top of the range of numbers (Long).
intervalThe given interval (Long).

REMARKS
* This function identifies the particular range in which a number falls and returns a string describing that range.
* If any of the arguments are Null, then Null is returned.
* If "start" <= 0, then a runtime error (5) occurs.
* If "stop <= "start", then a runtime error (5) occurs.
* If "interval" = 1, then the range is "number":"number" regardless of the "start" and "stop" values.
* If any of the arguments are Null, then Null is returned.
* This function always returns a range that has the same number of characters to the left and right of the colon.
* This function is often used in SQL SELECT queries as a way of showing data in ranges.
* The equivalent .NET function is Microsoft.VisualBasic.Interaction.Partition
* For the Microsoft documentation refer to learn.microsoft.com

Debug.Print Partition(0, 0, 5, 1)  '0: 0  
Debug.Print Partition(1, 0, 5, 1) '1: 1
Debug.Print Partition(2, 0, 5, 1) '2: 2
Debug.Print Partition(3, 0, 5, 1) '3: 3
Debug.Print Partition(4, 0, 5, 1) '4: 4
Debug.Print Partition(5, 0, 5, 1) '5: 5

''this number is before the first range
Debug.Print Partition(-1, 0, 5, 1) ':-1

''this number is after the last range
Debug.Print Partition(6, 0, 5, 1) '6:

'this number is in the second range
Debug.Print Partition(10, 0, 100, 10) '10: 19

'this number is in the last range
Debug.Print Partition(99, 0, 100, 10) '90: 99

Debug.Print Partition(0, -1, 5, 1) 'run-time error
Debug.Print Partition(0, -1, -5, 0) 'run-time error
Debug.Print Partition(99, 1.5, 9.9, 0) 'run-time error

SELECT DISTINCTROW Partition([freight],0, 500, 50) AS Range,
Count(Orders.Freight) AS Count
FROM Orders
GROUP BY Partition([freight],0,500,50);

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top