Solved

Informix - How to return table from procedure

Posted on 2014-04-09
4
424 Views
Last Modified: 2014-10-17
Hi All

(Warning:  SQL expert, Informix N00b)

I'm attempting to create a procedure where it returns a table of data, based on my experience with SQL Server doing the same, and could use some help.

From the '-- up to this point the proc' on down, can someone show me the syntax for a SELECT statement to be returned as a set?

Thanks in advance.
Jim

CREATE PROCEDURE rpt_sales_distribution (iYear int, iMonth int) AS

BEGIN

define iYear integer = 2014;
define iMonth integer = 4;
define iWeekNumber integer = 1;

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;

-- up to this point the proc saves fine, but I'd like to make it return the below set
select 1 as week_id,
       11 as src_id, 
       '11 SY Agt Portal' as src_name 
      ,count(*) as seg
      ,sum(a.unitrate) as rev
      ,round(sum(a.unitrate)/count(*)) as avg
  from wsord_det a
      ,wsord_hdr b
      ,wsord_tkt c
 where b.orddate between dtStart_week1 and dtEnd_week1 

Open in new window

0
Comment
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
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 41

Assisted Solution

by:Sharath
Sharath earned 500 total points
ID: 39992753
By using dtStart and dtEnd in the WHERE clause, Are you not getting what you want?
select 1 as week_id,
       11 as src_id, 
       '11 SY Agt Portal' as src_name 
      ,count(*) as seg
      ,sum(a.unitrate) as rev
      ,round(sum(a.unitrate)/count(*)) as avg
  from wsord_det a
      ,wsord_hdr b
      ,wsord_tkt c
 where b.orddate between dtStart and dtEnd

Open in new window

0
 
LVL 65

Author Comment

by:Jim Horn
ID: 40006792
(Sorry for the delay)

The below SQL returns a set
select 1 as week_id,
       11 as src_id, 
       '11 SY Agt Portal' as src_name 
      ,count(*) as seg
      ,sum(a.unitrate) as rev
      ,round(sum(a.unitrate)/count(*)) as avg
  from wsord_det a
      ,wsord_hdr b
      ,wsord_tkt c
 where b.orddate between dtStart and dtEnd

Open in new window

When I try to use variables here's the result..Returns multiple 'A syntax error has occured' lines
0
 
LVL 41

Accepted Solution

by:
Sharath earned 500 total points
ID: 40013263
try this.
define dtStart DATETIME YEAR TO DAY, dtEnd DATETIME YEAR TO DAY

let dtStart = '2017-04-01'
let dtEnd = '2014-04-07'

select 1 as week_id,
       11 as src_id, 
       '11 SY Agt Portal' as src_name 
      ,count(*) as seg
      ,sum(a.unitrate) as rev
      ,round(sum(a.unitrate)/count(*)) as avg
  from wsord_det a
      ,wsord_hdr b
      ,wsord_tkt c
 where b.orddate between dtStart and dtEnd

Open in new window

0
 
LVL 65

Author Closing Comment

by:Jim Horn
ID: 40387308
I've moved to a different gig and can't continue this issue, so I'm going to close the question and spread the wealth around.  Thanks.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
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…

732 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