Example: Inventory Status at the Beginning of Each Week in a Month - Advanced SQL Engine - Teradata Database

SQL Date and Time Functions and Expressions

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-24
dita:mapPath
xmd1556127764262.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1211
lifecycle
previous
Product Category
Teradata Vantageā„¢

The following example shows the inventory status at the beginning of each week for the month of September, 2011 for each business calendar setting.

SEL Item, BEGIN(week_duration) AS WeekBegin, Inventory
FROM Inventory_Tbl
EXPAND ON Duration AS week_duration
BY ANCHOR WEEK_BEGIN;

Inventory_Tbl

Item Duration Inventory
101 2011-09-01, 2011-09-05 12
101 2011-09-05, 2011-09-12 18
101 2011-09-12, 2011-09-18 15
101 2011-09-18, 2011-09-21 11

Sep-2011 Calendar

S M T W T F S
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  
SET SESSION CALENDAR = Teradata;
Item WeekBegin Inventory
101 2011-09-04 12
101 2011-09-11 18
101 2011-09-18 11
SET SESSION CALENDAR = ISO;
Item WeekBegin Inventory
101 2011-09-05 18
101 2011-09-12 15
101 2011-09-19 11
SET SESSION CALENDAR = Compatible;
Item WeekBegin Inventory
101 2011-09-03 12
101 2011-09-10 18
101 2011-09-17 15