[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
Solved

# What's the informix SQL for end of month?

Posted on 2014-04-07
Medium Priority
645 Views
Hi All

I'm butchering my way through creating my first Informix procedure (SQL expert, Informix N00b) and I'm passing a year and month as integers.

Question:  Given year and month number, what's the function for automagically determining the last day of that year-month?  For example, year=2010 and month=9 should return the date 2010-09-30.  Should go in line 17 of the below code block.

Thanks.
Jim

CREATE PROCEDURE informix.sales_distribution(iYear int, iMonth int, iWeekNumber int)

define dtStart DATETIME YEAR TO DAY;
define dtEnd DATETIME YEAR TO DAY;

if iWeekNumber = 1 then
let dtStart = to_date(to_char(iYear) || "-" || to_char(iMonth) + || "-01")
let dtEnd = to_date(to_char(iYear) || "-" || to_char(iMonth) + || "-07")
elseif iWeekNumber = 2 then
let dtStart = to_date(to_char(iYear) || "-" || to_char(iMonth) + || "-08")
let dtEnd = to_date(to_char(iYear) || "-" || to_char(iMonth) + || "-14")
elseif iWeekNumber = 3 then
let dtStart = to_date(to_char(iYear) || "-" || to_char(iMonth) + || "-15")
let dtEnd = to_date(to_char(iYear) || "-" || to_char(iMonth) + || "-21")
elseif iWeekNumber = 4 then
let dtStart = to_date(to_char(iYear) || "-" || to_char(iMonth) + || "-22")
let dtEnd = to_date(to_char(iYear) || "-" || to_char(iMonth) + || "-07")   -- ????
end if;
0
Question by:Jim Horn
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 6

Accepted Solution

Dulton earned 2000 total points
ID: 39983835
wrap what you're assigning dtEnd on line 17 in LAST_DAY(), it takes a date or datetime argument.

CREATE PROCEDURE informix.sales_distribution(iYear int, iMonth int, iWeekNumber int)

define dtStart DATETIME YEAR TO DAY;
define dtEnd DATETIME YEAR TO DAY;

if iWeekNumber = 1 then
let dtStart = to_date(to_char(iYear) || "-" || to_char(iMonth) + || "-01")
let dtEnd = to_date(to_char(iYear) || "-" || to_char(iMonth) + || "-07")
elseif iWeekNumber = 2 then
let dtStart = to_date(to_char(iYear) || "-" || to_char(iMonth) + || "-08")
let dtEnd = to_date(to_char(iYear) || "-" || to_char(iMonth) + || "-14")
elseif iWeekNumber = 3 then
let dtStart = to_date(to_char(iYear) || "-" || to_char(iMonth) + || "-15")
let dtEnd = to_date(to_char(iYear) || "-" || to_char(iMonth) + || "-21")
elseif iWeekNumber = 4 then
let dtStart = to_date(to_char(iYear) || "-" || to_char(iMonth) + || "-22")

let dtEnd = LAST_DAY(to_date(to_char(iYear) || "-" || to_char(iMonth) + || "-07"))
end if;

http://pic.dhe.ibm.com/infocenter/idshelp/v115/index.jsp?topic=%2Fcom.ibm.sqls.doc%2Fids_sqs_1538.htm
0

LVL 66

Author Comment

ID: 39983865
... looking ...
0

LVL 143

Expert Comment

ID: 40396759
I've requested that this question be closed as follows:

Accepted answer: 500 points for Dulton's comment #a39983835

for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

LVL 66

Author Closing Comment

ID: 40396760
I moved on to a different gig and can't verify this, but I suspect this is the correct answer.  Thanks.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
###### Suggested Courses
Course of the Month13 days, 22 hours left to enroll