July 2010
Intermediate to advanced
840 pages
16h 33m
English
Another common set of functions, which are not represented in standard SQL, deal with weeks. For example, Sybase’s SQL Anywhere (née WATCOM SQL) has a DOW(<date>) that returns a number between 1 and 7 to represent the day of the week (1 = Sunday, 2 = Monday, . . ., 7 = Saturday, following an ISO standard convention). You can also find functions that add or subtract weeks from a date given the number of the date within the year and so on. The function for finding the day of the week for a date is called Zeller’s algorithm:
CREATE FUNCTION Zeller (IN z_year INTEGER, IN z_month INTEGER, IN z_day INTEGER) RETURNS INTEGER LANGUAGE SQL DETERMINISTIC BEGIN DECLARE m INTEGER; DECLARE d INTEGER; DECLARE y INTEGER; SET y ...
Read now
Unlock full access