Solved

What's the informix SQL for end of month?

Posted on 2014-04-07
5
556 Views
Last Modified: 2014-10-22
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;

Open in new window

0
Comment
Question by:Jim Horn
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
Dulton earned 500 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; 

Open in new window


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

Author Comment

by:Jim Horn
ID: 39983865
... looking ...
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
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 65

Author Closing Comment

by:Jim Horn
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now