To browse a queue table, select from it.
The following queries peek at a queue without consuming rows.
- Determine the queue depth of a queue table by using the COUNT(*) aggregate function:
SELECT COUNT(*) FROM myqueue;
If the depth is zero, the system puts a consume mode SELECT statement into a delayed state.
- Peek at the next row set to be consumed from the queue table:
SELECT * FROM shoppingcart WHERE qits = (SELECT MIN(qits) FROM shoppingcart);
- Select only the next ten rows to be consumed:
SELECT TOP 10 * FROM myqueue ORDER BY QITS;
- Return the entire queue in FIFO order:
SELECT * FROM myqueue ORDER BY myqueue_qits;
- The duration of a queue table measures the age of the top queue table row.
Determine the duration of a queue table:
SELECT TOP 1 CURRENT_TIMESTAMP, qits, (CURRENT_TIMESTAMP - qits) DAY(4) TO SECOND AS queue_duration FROM shoppingcart ORDER BY qits;
The result is similar to this:
*** Query completed. One row found. 3 columns returned. Current Timestamp (6) 2004-05-19 14:30:01.420000+00:00 Q Insertion Time 2004-05-18 08:44:19.460000 queue_duration 1 05:45:41.960000