Oracle SQl query to find date range based on another cloumn value
Hi Folks,
I want to extract records for the employees who have consecutive vacation/leave from a table. If an emp has vacation of 3 days (MON-WED), the table contains 3 distinct records for him,
e.g. My table contains records as shown below.
EmpName Paycode ApplyDate Amt. of Hrs
emp1 vacation 5/1/2010 8
emp1 vacation 5/2/2010 8
emp1 vacation 5/3/2010 8
I am trying to get the output like this...
Emp Name Paycode Leave Start Date Leave End Date TotalHrs
emp1 vacation 5/1/2010 5/3/2010 24
Note: If the smae emp has sets of vacation in another month, that should come as a separate record with start date and end date(last date of vacation for that set).
I have a query which does not return any rows. Any help to repair this query or any better one would be of great help.
==================================================================
WITH vpt AS (
select personnum as empname, paycodename as paycode, applydate, timeinseconds/3600 as numhours from VP_TOTALS
where applydate between to_date('05/01/2010','MM/DD/YYYY') AND to_date('12/31/2010','MM/DD/YYYY')
AND paycodename in ('US-Vacation','US-Bereavement','US-Sick','US-Jury Duty')
select
empname,
paycode,
min(applydate) as startdate,
max(applydate) as enddate,
sum(numhours) as totalhours
from (
select
empname,
paycode,
applydate,
numhours,
-- number the blocks sequentially
sum(is_block_start) over (partition by empname, paycode order by applydate) as block_num
from (
select
empname,
paycode,
applydate,
numhours,
-- Mark the start of each block
case
when applydate = prev_applydate + 1 then 0 else 1 end as is_block_start
from (
select
empname,
paycode,
applydate,
numhours,
lag (applydate) over (partition by empname, paycode order by applydate) prev_applydate
from vpt
group by empname, paycode, block_num
===================================================================
Thanks,
Maha
Hi Dear,
Can I do reverse I mean I can get output as your question from your output as below:
I have this table
FID STARTD ATE END DATE
1 01-MAY-10 03-MAY-10
1 09-MAY-10 11-MAY-10
1 03-JUN-10 04-JUN-10
2 03-JUN-10 04-JUN-10
2 04-AUG-10 04-AUG-10
2 06-AUG-10 06-AUG-10
I want like this.
FID FDATE
1 01-MAY-10
1 02-MAY-10
1 03-MAY-10
1 09-MAY-10
1 10-MAY-10
1 11-MAY-10
1 03-JUN-10
1 04-JUN-10
2 03-JUN-10
2 04-JUN-10
2 04-AUG-10
2 06-AUG-10
And:
How can i get date wise entry from Joining date to relieving date like..
FID START DATE END DATE
1 01-MAY-10 03-MAY-12
1 09-MAY-10 11-MAY-11
2 04-AUG-10 04-AUG-11
I want like this.
FID FDATE
1 01-MAY-10
1 03-MAY-10
1 04-MAY-10
1 05-MAY-10
1 16-MAY-10
1 17-MAY-10
1 08-May-10
1 09-May-10
1 03-May-12
Can you please help me.
Thanks,
Edited by: 978452 on Dec 24, 2012 12:02 AM
Similar Messages
-
Why does Oracle SQL query returning a date field without the time component
Hi,
I'm a novice SQL user & hv just installed Oracle SQL developer (Version 3.0.04, Build MAIN-04.34).
I made the same SQL query using "Oracle SQL developer" & "TOAD for Oracle 9.0.1" but I got 2 different format on the same date field:
On TOAD, I get the date field extracted as *04/26/2011 23:12:58*
On Oracle, I get the date field extracted as *26/APR/11*
Why is the Oracle result in a different format & missing the time component?
Is there any option/preference that I need to set in Oracle SQL developer to get the full date/time format displayed?
I've tried to set my the date format to DD/MON/RR HH12:MI:SSXFF AM under the preference -> database NLS but I still get the same format!
Plse help!hokim wrote:
Hi,
I'm a novice SQL user & hv just installed Oracle SQL developer (Version 3.0.04, Build MAIN-04.34).
I made the same SQL query using "Oracle SQL developer" & "TOAD for Oracle 9.0.1" but I got 2 different format on the same date field:
On TOAD, I get the date field extracted as *04/26/2011 23:12:58*
On Oracle, I get the date field extracted as *26/APR/11*
Why is the Oracle result in a different format & missing the time component?
Is there any option/preference that I need to set in Oracle SQL developer to get the full date/time format displayed?
I've tried to set my the date format to DD/MON/RR HH12:MI:SSXFF AM under the preference -> database NLS but I still get the same format!
Plse help!http://edstevensdba.wordpress.com/category/nls_date_format/ -
SQL Query to get Date Range Values
Hi,
The database is Oracle11i.
I am looking for a way to generate list of dates from a fixed date in the past (could be hardcoded) to current day (sysdate).
That is, if the fixed date is 19 June 2011 and assuming that today is 24 June 2011 the SQL should be able to generate the
following:-
19-June-2011
20-June-2011
21-June-2011
22-June-2011
23-June-2011
24-June-2011
And the constraint is that I can't make any change to the database in question. I can only fire an SQL query (SELECT). No
usage of time dimension kind of approach (time dimension is not available here) and no procedures, PL/SQL etc. Is there any way?
ThanksJaimeen Shah wrote:
Hi,
The database is Oracle11i.
I am looking for a way to generate list of dates from a fixed date in the past (could be hardcoded) to current day (sysdate).
That is, if the fixed date is 19 June 2011 and assuming that today is 24 June 2011 the SQL should be able to generate the
following:-
19-June-2011
20-June-2011
21-June-2011
22-June-2011
23-June-2011
24-June-2011
And the constraint is that I can't make any change to the database in question. I can only fire an SQL query (SELECT). No
usage of time dimension kind of approach (time dimension is not available here) and no procedures, PL/SQL etc. Is there any way?
Thanks
SQL> def date_start = '13/11/2010'
SQL> def date_end = '22/11/2010'
SQL> with
2 data as (
3 select to_date('&date_start', 'DD/MM/YYYY') date1,
4 to_date('&date_end', 'DD/MM/YYYY') date2
5 from dual
6 )
7 select to_char(date1+level-1, 'DD/MM/YYYY') the_date
8 from data
9 connect by level <= date2-date1+1
10 /
THE_DATE
13/11/2010
14/11/2010
15/11/2010
16/11/2010
17/11/2010
18/11/2010
19/11/2010
20/11/2010
21/11/2010
22/11/2010 -
Query to find numeric range gaps within another range
Hi All,
Is it possible to find the solution with a SQL query for the following scenario.
I have done it in PL/SQL but want to do it in SQL. I have tried with analytic functions but not able to find the expected results.
Suppose i have a Table A with below data
Range_Start Range_End
4 16
20 100
101 200
250 300
And Table B with below data
SubRange_Start SubRange_End
7 9
10 13
20 60
70 80
110 190
270 300
i want to find the missing gaps in Table B within the ranges specified in Table A, like below
Output
start end
4 6
14 16
61 69
81 100
101 109
191 200
250 269Hi Dear,
Can I do reverse I mean I can get output as your question from your output as below:
I have this table
FID STARTD ATE END DATE
1 01-MAY-10 03-MAY-10
1 09-MAY-10 11-MAY-10
1 03-JUN-10 04-JUN-10
2 03-JUN-10 04-JUN-10
2 04-AUG-10 04-AUG-10
2 06-AUG-10 06-AUG-10
I want like this.
FID FDATE
1 01-MAY-10
1 02-MAY-10
1 03-MAY-10
1 09-MAY-10
1 10-MAY-10
1 11-MAY-10
1 03-JUN-10
1 04-JUN-10
2 03-JUN-10
2 04-JUN-10
2 04-AUG-10
2 06-AUG-10
And:
How can i get date wise entry from Joining date to relieving date like..
FID START DATE END DATE
1 01-MAY-10 03-MAY-12
1 09-MAY-10 11-MAY-11
2 04-AUG-10 04-AUG-11
I want like this.
FID FDATE
1 01-MAY-10
1 03-MAY-10
1 04-MAY-10
1 05-MAY-10
1 16-MAY-10
1 17-MAY-10
1 08-May-10
1 09-May-10
1 03-May-12
Can you please help me.
Thanks,
Edited by: 978452 on Dec 24, 2012 12:02 AM -
Oracle sql function to find VARCHAR2 data is numeric
Hi Everyone,
Is there oracle sql function to find whether the VARCHAR2 data is numeric?
Thankshi,
see the below example .
with t as
(select '12' as col from dual union all
select '1 2' as col from dual union all
select '2 1 3' as col from dual union all
select 'abcde' as col from dual union all
select '12345' as col from dual union all
select '1a4A5' as col from dual union all
select '12a45' as col from dual union all
select '12aBC' as col from dual union all
select '12abc' as col from dual union all
select '12ab5' as col from dual union all
select '12aa5' as col from dual union all
select '12AB5' as col from dual union all
select 'ABCDE' as col from dual union all
select '123-5' as col from dual union all
select '12.45' as col from dual union all
select '1a4b5' as col from dual union all
select '1 3 5' as col from dual union all
select '1 45' as col from dual union all
select '1 5' as col from dual union all
select 'a b c d' as col from dual union all
select 'a b c d e' as col from dual union all
select 'a e' as col from dual union all
select 'Steven' as col from dual union all
select 'Stephen' as col from dual union all
select '111.222.3333' as col from dual union all
select '222.333.4444' as col from dual union all
select '333.444.5555' as col from dual union all
select 'abcdefabcdefabcxyz' as col from dual union all
select 'aaa' as col from dual union all
select 'ddd' as col from dual union all
select 'ccc' as col from dual union all
select 'aaaaa' as col from dual union all
select 'aaaaaaaa' as col from dual
select * from t where regexp_like(col,'[1-9]')
Result
COL
12
1 2
2 1 3
12345
1a4A5
12a45
12aBC
12abc
12ab5
12aa5
12AB5
123-5
12.45
1a4b5
1 3 5
1 45
1 5
111.222.3333
222.333.4444
333.444.5555Thanks,
P Prakash -
SQL query to find sqlnet.ora parameters
Hi All,
I am working 11g RAC /solaris 9
I want have sql query to find values of sqlnet.ora parameters
May be values of SQLNET.INBOUND_CONNECT_TIMEOUT
SQLNET.SEND_TIMEOUT, SQLNET.RECV_TIMEOUT
Thanks
rajThe sqlnet.ora file is the profile configuration file. It resides on the client machines and the database server.
Profiles are stored and implemented using this file. The database server can be configured with access control parameters in the sqlnet.ora file.
These parameters specify whether clients are allowed or denied access based on the protocol.
The sqlnet.ora file enables you to do the following:
Specify the client domain to append to unqualified names
Prioritize naming methods
Enable logging and tracing features
Route connections through specific processes
Configure parameters for external naming
Configure Oracle Advanced Security
Use protocol-specific parameters to restrict access to the database
By default, the sqlnet.ora file is located in the ORACLE_HOME/network/admin directory. The sqlnet.ora file can also be stored in the directory specified by the TNS_ADMIN environment variable.
You can not query on this file sqlnet.ora as tnsnames.ora file.
Regards
Mahir M. Quluzade -
SQL Query to find menus and submenus attached to responsibility
Hi,
I am looking for help to find out a sql query to pull out the list of all the menu's associated with each of the responsibilities assigned to users. Please let me know any SQL query to find out menus attached for responsibilities assigned to users.835129 wrote:
I was asked by my lead to list out responsibilities and attached menus and I was asked to submit the output from production. In the metalink note provided by you it was asked to create table collecting all menu id's and I cannot create any tables in production. Apart from this there were 1000's of users with different responsibilities and different menus. I cannot collect all of the users menu ids.
I just want to list out responsibilities and attached menus. Is that something you can helpout withhttps://forums.oracle.com/forums/search.jspa?threadID=&q=fnd_responsibility_vl+AND+fnd_menu&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
https://forums.oracle.com/forums/search.jspa?threadID=&q=fnd_responsibility_tl+AND+FND_MENU_ENTRIES_TL&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
Please search the forum for these tables/views and you should get many hits:
FND_MENU_ENTRIES_TL
FND_MENU_ENTRIES_VL
FND_RESPONSIBILITY_TL
FND_RESPONSIBILITY_VL
Thanks,
Hussein -
Sql query to find all contacts for an account
I wonder if someone wrote an sql query to find all contacts for an account number in Oracle customer master. We are on EBS 11.5.10.
I am also looking for sql query to find all ship to addresses for an account number.
Thanks.Can you also post the query for people who read this post and are also looking for an answer?
Regards,
Johan Louwers. -
How will write SQL query to fetch data from each Sub-partition..
Hi All,
Anyone does have any idea about How to write SQL query to fetch data from Sub-partition.
Actually i have one table having composite paritition(Range+list)
Now if i want to fetch data from main partition(Range) the query will be
SELECT * FROM emp PARTITION(q1_2005);
Now i want to fetch data at sub-partition level(List) .But i am not able to get any SQL query for that.
Pls help me to sort out.
Thanks in Advance.
AnwarSELECT * FROM emp SUBPARTITION(sp1);
-
SQl query to find incompatibility defined
If two programs are defined as incompatible with one another, the data these programs cannot access simultaneously must also be identified.
This can be found from concurrent program->define from front end ebs login, but is there any SQL query to find this for a particular program or request set??
Thanks in advance.Please search the forum before posting similar questions.
Concurrent-Conflict
Re: Concurrent-Conflict
Thanks,
Hussein -
How to run recordset SQL query in FORM DATA event
How can I run recordset SQL query in FORM DATA event upon clicking on Add button in the document?
Hi Slamet,
When you receive a form data event you have a class containing inside it a ObjectKeys xml info regarding the object added/modified,...
With the objects keys you can then use the DI API method called GetByKeys to obtain the DI Object.
There is some information about it in the SDK Help file, mainly in the "FormDataEvent" class definition:
<i>The event provides the unique ID (BusinessObjectInfo.ObjectKey) of the modified business object. You can use the value of this property as an input parameter in the DI API DataBrowser.GetByKeys method to get a DI object.</i>
Pay attention you don't have this information in the Before=True event of the Add as it is not yet in the database.
Hope it helps
Trinidad. -
Sql query to find the balances for a customer account wise.
Hi,
Could someone help me with the sql query to find the balances for each customer account wise. This is need to generate the report.
presently we are using this query, but the output doesnot return the expected result.
SELECT sum(nvl(ps.acctd_amount_due_remaining,0)) "Balance"
FROM ra_cust_trx_line_gl_dist_all gld,
gl_code_combinations c,
ar_payment_schedules_all ps,
RA_CUSTOMER_TRX_ALL rat,
ra_customers rc
WHERE c.CHART_OF_ACCOUNTS_ID = 101
and gld.code_combination_id = c.code_combination_id
and rat.CUSTOMER_TRX_ID=gld.CUSTOMER_TRX_ID
and rat.CUSTOMER_TRX_ID=ps.CUSTOMER_TRX_ID
and ps.customer_id=rc.customer_id
and ps.status='OP'
and ps.gl_date <= :PDATE
and ps.org_id=:PORGID
and ps.class in ('GUAR','INV','DM','DEP')
and c.SEGMENT4=:Account_id
and ps.customer_id=:Customer_id
Thanks in advance.
Kalyan.Can someone help us with this.
-
Newbie blues: Oracle Sql Developer showing different data from Sqlplus.
Newbie blues: Oracle Sql Developer showing different data from Sqlplus.
First of all; it would be difficult to know less about Oracle than myself.
I just installed a recent copy of the server and am running SQl Developer 3.2.20.10.
I made a small test table , borrowed some pl sql code to add rows, then wrote code to delete some rows. Lots of fun.
In SQL Developer “Select * from t1;” now shows 7 records, which seems right.
I wanted other views of the data and so logged in from the command line using SQLPlus.
The same code here shows the table prior to the delete, with 600 plus rows. Needless to say I’ve logged out and back in again, with no changes.
No fun ! What am I not understanding here ?5e33d18c-3b32-48d4-82a7-676feeaa97c9 wrote:
Newbie blues: Oracle Sql Developer showing different data from Sqlplus.
First of all; it would be difficult to know less about Oracle than myself.
I just installed a recent copy of the server and am running SQl Developer 3.2.20.10.
I made a small test table , borrowed some pl sql code to add rows, then wrote code to delete some rows. Lots of fun.
In SQL Developer “Select * from t1;” now shows 7 records, which seems right.
I wanted other views of the data and so logged in from the command line using SQLPlus.
The same code here shows the table prior to the delete, with 600 plus rows. Needless to say I’ve logged out and back in again, with no changes.
No fun ! What am I not understanding here ?
Others sessions never see uncommitted data
> then wrote code to delete some rows. Lots of fun.
did you ever actually issue COMMIT so other session can see the changed data? -
Can anybody provide the SQL query to find the files uploaded in a particular folder?
Hi All,
Can anybody provide the SQL query to find the documents (document name) uploaded in a particular folder? While clicking on folder in
GUI I'm hitting the Timeout error. I would like to find the files uploaded into this folder from SQLPLUS.
Any help is greatly appreciated.
With best regards,
NevinNevin,
Be great if we could know the version of Portal. For Rel. 1, here's the query
select id,masterthingid from wwv_things
where siteid = &site
and cornerid = &corner
&site - Content Area id
&corner - Folder id
if you don't know the folder id, use
select id from wwv_corners where siteid = &site
and name = &folder
Hope this helps. I have run into this situation before. Usually, the culprits were
one of the following:
1. Junk Characters in description of item (caused due to Copy-Paste)
2. Special Characters in the File name
Hi All,
Can anybody provide the SQL query to find the documents (document name) uploaded in a particular folder? While clicking on folder in
GUI I'm hitting the Timeout error. I would like to find the files uploaded into this folder from SQLPLUS.
Any help is greatly appreciated.
With best regards,
Nevin -
Sql query need for date format''Mon 23 Apr 16:45 pm'
i need SQL query to print date like 'Mon 23 Apr 16:45 pm' format
SQL> select to_char(sysdate,'Dy fmddfm Mon hh24:mi pm','nls_date_language=american') from dual
2 /
TO_CHAR(SYSDATE,'DY
Fri 27 Apr 13:04 pm
1 rij is geselecteerd.Regards,
Rob.
Maybe you are looking for
-
Why do we create logical systems in ALE?
Hi All, i got this question in interview. Why do we create logical systems in ALE? Thanks & Regards suresh
-
my itunes will not open at all. it occasionally will open but when i plug my iphone into it the program freezes and crashes. please help as soon as possible
-
My iMac G5 is unpredictably experiencing a kernal panic. I can not resolve the problem. The Apple Genius guys on Chestnut SF tell me it's not a hardware problem, but I'm not sure. I re-installed Leopard. It still happens. Sometimes at login. Sometime
-
Upgrade Acrobat 7 Pro (Mac OS10.6) to Acrobat X
I used to work on Mac Os 10.6 with Adobe Acrobat 7 Professional, but when I tried to install it with my new Mac (OS 10.7) it tells me that PowerPC is not available. Should I buy Acrobat X or is there a way to upgrade my Acrobat software to be compati
-
Report Builder 3.0 Category Listing
. I have a budget report assembled with user drop-down parameters of "Budget Year", "Budget Department", and "Departmental Category". The report runs just fine with a single selected "Departmental Category" but if I select multiple "Departmental Cat