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 |
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 #123823 is a reply to message #123820] |
Wed, 15 June 2005 00:49 |
|
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
|
|
|
Goto Forum:
Current Time: Sat Feb 01 10:01:21 CST 2025
|