To get start and end date of month [message #639343] |
Mon, 06 July 2015 07:08 |
|
rohit_shinez
Messages: 139 Registered: January 2015
|
Senior Member |
|
|
Hi,
I need to take the start and end date of month by referring to ref_table
TYPE CODE VALUE
MISSING_RECORD AUG_2010 AUGUST 2010
CREATE TABLE "REF_TABLE"
(
"TYPE" VARCHAR2(20 BYTE) NOT NULL ENABLE,
"CODE" VARCHAR2(20 BYTE) NOT NULL ENABLE,
"VALUE" VARCHAR2(100 BYTE)
);
Insert into Ref_table (TYPE,CODE,VALUE) values ('MISSING_RECORD','AUG_2010','AUGUST 2010');
I Need to derive first date and last date from ref_table where value = AUGUST 2010
output
|
|
|
|
|
|
|
|
|
Re: To get start and end date of month [message #639351 is a reply to message #639346] |
Mon, 06 July 2015 07:38 |
Solomon Yakobson
Messages: 3273 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
Obviously you are getting errors. You are storing date in VARCHAR2 column - bad design. Change column VALUE type to DATE. Otherwise:
SELECT TO_CHAR(TRUNC(TO_DATE(VALUE,'Month YYYY'),'mm'),'fmMonth DD, YYYY'),
TO_CHAR(LAST_DAY(TRUNC(TO_DATE(VALUE,'Month YYYY'),'mm')),'fmMonth DD, YYYY')
FROM ref_table
WHERE code = 'MISSING_RECORD';
SY.
|
|
|
|
|
|
Re: To get start and end date of month [message #639365 is a reply to message #639361] |
Mon, 06 July 2015 08:15 |
|
rohit_shinez
Messages: 139 Registered: January 2015
|
Senior Member |
|
|
yeah i agree with you i wanted to compare with output from below query from the query
select 1 from Main_table
where col_1 not between values from second query
SELECT TRUNC(TO_DATE(VALUE,'Month YYYY'),'mm'),
LAST_DAY(TRUNC(TO_DATE(VALUE,'Month YYYY'),'mm')) FROM
ref_table where type = 'MISSING_RECORD';
[Updated on: Mon, 06 July 2015 09:29] Report message to a moderator
|
|
|
|
|
|
|
Re: To get start and end date of month [message #639383 is a reply to message #639376] |
Mon, 06 July 2015 10:06 |
|
rohit_shinez
Messages: 139 Registered: January 2015
|
Senior Member |
|
|
i would like to exclude the records from main_table
CREATE TABLE "MAIN_TABLE"
(
"INT_AMT" NUMBER(12,2),
"CHARGE_END_DATE" DATE,
"NO_OF_PARTIES" NUMBER(3,0),
"CHARGE_START_DATE" DATE
);
Insert into MAIN_TABLE (INT_AMT,CHARGE_END_DATE,NO_OF_PARTIES,CHARGE_START_DATE) values (0,to_date('30/09/2005','DD/MM/YYYY'),2,to_date('31/10/2005','DD/MM/YYYY'));
Insert into MAIN_TABLE(INT_AMT,CHARGE_END_DATE,NO_OF_PARTIES,CHARGE_START_DATE) values (0,to_date('01/12/2005','DD/MM/YYYY'),2,to_date('29/12/2005','DD/MM/YYYY'));
Insert into MAIN_TABLE (INT_AMT,CHARGE_END_DATE,NO_OF_PARTIES,CHARGE_START_DATE) values (0,to_date('01/11/2005','DD/MM/YYYY'),2,to_date('30/11/2005','DD/MM/YYYY'));
i need to exclude those records where charge_start_date falling between '01-AUG-2010' and '31-AUG-2010'
[Updated on: Mon, 06 July 2015 10:07] Report message to a moderator
|
|
|
|
Re: To get start and end date of month [message #639385 is a reply to message #639384] |
Mon, 06 July 2015 10:22 |
|
rohit_shinez
Messages: 139 Registered: January 2015
|
Senior Member |
|
|
something like below where i am struck actually
select * from summary sum,
(SELECT TRUNC(TO_DATE(VALUE,'Month YYYY'),'mm') START_DATE,
LAST_DAY(TRUNC(TO_DATE(VALUE,'Month YYYY'),'mm')) END_DATE FROM
Ref_table ref WHERE TYPE = 'MISSING_RECORD') ps
and sum.charge_start_date not between ps.start_date and ps.end_date
i am not getting if there are two records in ref_table like below
Insert into Ref_table (TYPE,CODE,VALUE) values ('MISSING_RECORD','SEP_2010','SEPTEMBER 2010');
|
|
|
|
|
|
|
|
|
|
|