Home » Developer & Programmer » Forms » HOW TO CHANGE THE SELECT COLUMNS DYNAMICALLY DEPENDING UPON THE PAAMETERS WE GIVE
HOW TO CHANGE THE SELECT COLUMNS DYNAMICALLY DEPENDING UPON THE PAAMETERS WE GIVE [message #123390] Mon, 13 June 2005 03:00 Go to next message
MEEENAR
Messages: 72
Registered: May 2005
Location: CHENNAI
Member
The query is

SELECT *
FROM (SELECT (SUBSTR(c.dcn_ent_ctrl_id,1,4)||'00000000')branch,
sum(decode(to_char(c.dcn_date,'mon'),'jan',c.dcn_brokerage_amt,0)) JANUARY,
sum(decode(to_char(c.dcn_date,'mon'),'feb',c.dcn_brokerage_amt,0)) FEBRUARY,
sum(decode(to_char(c.dcn_date,'mon'),'mar',c.dcn_brokerage_amt,0)) MARCH,
sum(decode(to_char(c.dcn_date,'mon'),'apr',c.dcn_brokerage_amt,0)) APRIL,
sum(decode(to_char(c.dcn_date,'mon'),'may',c.dcn_brokerage_amt,0)) MAY,
sum(decode(to_char(c.dcn_date,'mon'),'jun',c.dcn_brokerage_amt,0)) JUNE,
sum(decode(to_char(c.dcn_date,'mon'),'jul',c.dcn_brokerage_amt,0)) JULY,
sum(decode(to_char(c.dcn_date,'mon'),'aug',c.dcn_brokerage_amt,0)) AUGUST,
sum(decode(to_char(c.dcn_date,'mon'),'sep',c.dcn_brokerage_amt,0)) SEPTEMBER,
sum(decode(to_char(c.dcn_date,'mon'),'oct',c.dcn_brokerage_amt,0)) OCTOBER,
sum(decode(to_char(c.dcn_date,'mon'),'nov',c.dcn_brokerage_amt,0)) NOVEMBER,
sum(decode(to_char(c.dcn_date,'mon'),'dec',c.dcn_brokerage_amt,0)) DECEMBER

FROM dtm_contract_note_master c, dtm_contract_note_details d
WHERE c.dcn_date BETWEEN :FROMDATE AND :TODATE
AND (SUBSTR(c.dcn_ent_ctrl_id,1,4)||'00000000') = :BRANCHID
and c.dcn_no=d.dcd_dcn_no
and SUBSTR(d.dcd_dcm_id,1,3)=NVL(:TTYPE,SUBSTR(d.dcd_dcm_id,1,3))

GROUP BY (SUBSTR(c.dcn_ent_ctrl_id,1,4)||'00000000') )
ORDER BY 1;


Here I am using 4 paramaeters fromdate,todate, branchid & ttype





Now I have a small problem ..

DEPENDING UPON THE PARAMETERS THE NO OF COLUMNS SELECTED SHOULD VARY DYNAMICALLY

If I give from date 15-jan-2005 and to date 25-may-2005 then

it should show me only the months pertaining to fromdate and todate that is it should me jan, feb , mar ,apr , may only

It should not show all the 12 months

Please help me to solve the problem


VERY VERY URGENT
Re: HOW TO CHANGE THE SELECT COLUMNS DYNAMICALLY DEPENDING UPON THE PAAMETERS WE GIVE [message #123602 is a reply to message #123390] Tue, 14 June 2005 02:22 Go to previous messageGo to next message
djmartin
Messages: 10181
Registered: March 2005
Location: Surges Bay TAS Australia
Senior Member
Account Moderator
Please stop reposting the same question. If you want it to 'float' your thread to the top of the forum just add a reply to your original question.

David
Re: HOW TO CHANGE THE SELECT COLUMNS DYNAMICALLY DEPENDING UPON THE PAAMETERS WE GIVE [message #123820 is a reply to message #123602] Wed, 15 June 2005 00:29 Go to previous messageGo to next message
MEEENAR
Messages: 72
Registered: May 2005
Location: CHENNAI
Member
I am really very sorry for reposting the query..

Please help me out to solve the problem
Re: HOW TO CHANGE THE SELECT COLUMNS DYNAMICALLY DEPENDING UPON THE PAAMETERS WE GIVE [message #123823 is a reply to message #123820] Wed, 15 June 2005 00:49 Go to previous message
djmartin
Messages: 10181
Registered: March 2005
Location: Surges Bay TAS Australia
Senior Member
Account Moderator
Okay .. as I said in your other thread ...

define the stem of your query
stmt := "SELECT * FROM (SELECT (SUBSTR(c.dcn_ent_ctrl_id,1,4)||'00000000') branch "

Need "from date 15-jan-2005 and to date 25-may-2005 "

then using the parameters and a loop

Date1 = from_date

LOOP while date1 < to_date_parm /* you will have to correct this lose logic */
  stmt := stmt ||
          ', sum( decode( to_char(c.dcn_date, ''yyyymon''), ''' ||
  /* now we have to build the format */
  to_char(date1,'yyyymon') || /* gives 2005jan */
  ''', c.dcn_brokerage_amt, 0 ) ) ' ||
  /* now we want the month as a label */
  to_char(date1,'MON'); /* gives JANUARY */
 
  /* increment month */
  add_months(date1, 1);
END LOOP

stmt := stmt ||
"FROM dtm_contract_note_master c, dtm_contract_note_details d
WHERE c.dcn_date BETWEEN :FROMDATE AND :TODATE
AND (SUBSTR(c.dcn_ent_ctrl_id,1,4)||'00000000') = :BRANCHID
and c.dcn_no=d.dcd_dcn_no
and SUBSTR(d.dcd_dcm_id,1,3)=NVL(:TTYPE,SUBSTR(d.dcd_dcm_id,1,3))

GROUP BY (SUBSTR(c.dcn_ent_ctrl_id,1,4)||'00000000') )
ORDER BY 1" /* you will have to add the concat pair for each line */

/* Now parse and execute the 'stmt' */



Now execute the 'stmt' to give you just the months and years between form and to date.

David

[Updated on: Wed, 15 June 2005 01:07]

Report message to a moderator

Previous Topic: how to display result of a dynamic select on a form?
Next Topic: printing oracle forms data to excel
Goto Forum:
  


Current Time: Fri Sep 20 01:30:28 CDT 2024