How to use SQL to display Datethat falls between the date range
Hi,
I'm figuring out how do i use SQL to select data
that falls between the date range stated
(for eg. 19/02/1955 to 19/02/2003)
I've tried :
sql="Select * From StudentRecords WHERE DOB BETWEEN #" jTextField21.getText() "#" +" And " +"#" +jTextField22.getText;
Using BETWEEN statment , but Between Statement isn't doing what i want..
even those out of range are displayed... any ideas how??
Thank yOU in advance!
oracle:
sql = "Select * From StudentRecords WHERE DOB between TO_DATE('07/04/2003','dd/mm/yyyy') and TO_DATE('08/04/2003','dd/mm/yyyy')";
Similar Messages
-
SUM(Case how to use this structure to get average values over date range
I am using:
Oracle SQL Developer (3.0.04) Build MAin-04.34 Oracle Database 11g Enterprise Edition 11.2.0.1.0 - 64bit Production
How do I use the sum function with a case structure inside.
so I have data that looks like has an ID, date, and value. I am looking to get the 7 day average for the date range of 4/1/2013 thru 4/20/2013
with t as (
select 1 ID_Key,to_date('4/1/2013','mm-dd-yyyy') date_val, 10 Value_num from dual union all
select 1 ID_key,to_date('4/2/2013','mm-dd-yyyy'), 15 from dual union all
select 1 ID_key,to_date('4/3/2013','mm-dd-yyyy'), 20 from dual union all
select 1 ID_key,to_date('4/5/2013','mm-dd-yyyy'), 0 from dual union all
select 1 ID_key,to_date('4/8/2013','mm-dd-yyyy'), 12 from dual union all
select 1 ID_key,to_date('4/9/2013','mm-dd-yyyy'), 8 from dual union all
select 1 ID_key,to_date('4/10/2013','mm-dd-yyyy'), 6 from dual union all
select 1 ID_key,to_date('4/12/2013','mm-dd-yyyy'), 10 from dual union all
select 1 ID_key,to_date('4/13/2013','mm-dd-yyyy'), 0 from dual union all
select 1 ID_key,to_date('4/14/2013','mm-dd-yyyy'), 0 from dual union all
select 1 ID_key,to_date('4/15/2013','mm-dd-yyyy'), 10 from dual union all
select 1 ID_key,to_date('4/16/2013','mm-dd-yyyy'), 5 from dual union all
select 1 ID_key,to_date('4/17/2013','mm-dd-yyyy'), 2 from dual union all
select 1 ID_key,to_date('4/20/2013','mm-dd-yyyy'), 3 from dual union all
select 2 ID_key,to_date('4/3/2013','mm-dd-yyyy'), 12 from dual union all
select 2 ID_key,to_date('4/5/2013','mm-dd-yyyy'), 15 from dual union all
select 2 ID_key,to_date('4/6/2013','mm-dd-yyyy'), 5 from dual union all
select 2 ID_key,to_date('4/7/2013','mm-dd-yyyy'), 7 from dual union all
select 2 ID_key,to_date('4/9/2013','mm-dd-yyyy'), 10 from dual union all
select 2 ID_key,to_date('4/11/2013','mm-dd-yyyy'), 5 from dual union all
select 2 ID_key,to_date('4/12/2013','mm-dd-yyyy'), 0 from dual union all
select 2 ID_key,to_date('4/13/2013','mm-dd-yyyy'), 0 from dual union all
select 2 ID_key,to_date('4/15/2013','mm-dd-yyyy'), 6 from dual union all
select 2 ID_key,to_date('4/16/2013','mm-dd-yyyy'), 8 from dual union all
select 2 ID_key,to_date('4/17/2013','mm-dd-yyyy'), 0 from dual union all
select 2 ID_key,to_date('4/18/2013','mm-dd-yyyy'), 10 from dual union all
select 2 ID_key,to_date('4/19/2013','mm-dd-yyyy'), 5 from dual
)**Please let me know if the table does not load.
I would like to get the 7 day average as long as there is date for that row has enough previous dates, it not then it will return null.
the results should look like this
ID_Key date_val Value_num 7Day_Avg 7Day_Avg2
1 4/1/2013 10 null null
1 4/2/2013 15 null null
1 4/3/2013 20 null null
1 4/5/2013 0 null null
1 4/8/2013 12 6.71 11.75
1 4/9/2013 8 5.71 10.00
1 4/10/2013 6 3.71 6.50
1 4/12/2013 10 5.14 9.00
1 4/13/2013 0 5.14 7.20
1 4/14/2013 0 5.14 6.00
1 4/15/2013 10 4.86 5.67
1 4/16/2013 5 4.42 5.17
1 4/17/2013 2 3.85 4.50
1 4/20/2013 3 2.86 4.00
2 4/3/2013 12 null null
2 4/5/2013 15 null null
2 4/6/2013 5 null null
2 4/7/2013 7 5.57 9.75
2 4/9/2013 10 7.00 9.80
2 4/11/2013 5 6.00 8.40
2 4/12/2013 0 3.86 5.40
2 4/13/2013 0 3.14 4.40
2 4/15/2013 6 3.00 4.20
2 4/16/2013 8 2.71 3.80
2 4/17/2013 0 2.71 3.17
2 4/18/2013 10 3.43 4.00
2 4/19/2013 5 4.14 4.83As you may notice, there are gaps in the dates, so the value are then treated as zeros for the 7Day_Avg and then ignored for teh 7Day_Avg2 (not counted as number of days averaged do to no valu_num row)
I was trying something like this to start, but getting error "missing keyword"
select
t.*/,
sum(
case
when date_val between :day2 - 6 and :day2
then value_num between date_val - 6 and date_val
else null
end
as 7Day_avg
form tShould I have the case structure outside the sum function?
Any thoughts??
Edited by: 1004407 on Jun 7, 2013 11:06 AMHi,
If you want the average of the last 7 days, including the current day, then then RANGE should be 6 PRECEDING, not 7.
Try this:
WITH got_min_date_val AS
SELECT id_key, date_val, value_num
, MIN (date_val) OVER () AS min_date_val
FROM t
WHERE date_val BETWEEN TO_DATE ('04-01-2013', 'mm-dd-yyyy')
AND TO_DATE ('04-20-2013', 'mm-dd-yyyy')
SELECT id_key, date_val, value_num
, CASE
WHEN date_val >= min_date_val + 6
THEN SUM (value_num) OVER ( PARTITION BY id_key
ORDER BY date_val
RANGE 6 PRECEDING
/ 7
END AS avg_7_day
, CASE
WHEN date_val >= min_date_val + 6
THEN AVG (value_num) OVER ( PARTITION BY id_key
ORDER BY date_val
RANGE 6 PRECEDING
END AS avg_7_day_2
FROM got_min_date_val
ORDER BY id_key
, date_val
Output:
ID_KEY DATE_VAL VALUE_NUM AVG_7_DAY AVG_7_DAY_2
1 01-APR-13 10
1 02-APR-13 15
1 03-APR-13 20
1 05-APR-13 0
1 08-APR-13 12 6.71 11.75
1 09-APR-13 8 5.71 10.00
1 10-APR-13 6 3.71 6.50
1 12-APR-13 10 5.14 9.00
1 13-APR-13 0 5.14 7.20
1 14-APR-13 0 5.14 6.00
1 15-APR-13 10 4.86 5.67
1 16-APR-13 5 4.43 5.17
1 17-APR-13 2 3.86 4.50
1 20-APR-13 3 2.86 4.00
2 03-APR-13 12
2 05-APR-13 15
2 06-APR-13 5
2 07-APR-13 7 5.57 9.75
2 09-APR-13 10 7.00 9.80
2 11-APR-13 5 6.00 8.40
2 12-APR-13 0 3.86 5.40
2 13-APR-13 0 3.14 4.40
2 15-APR-13 6 3.00 4.20
2 16-APR-13 8 2.71 3.80
2 17-APR-13 0 2.71 3.17
2 18-APR-13 10 3.43 4.00
2 19-APR-13 5 4.14 4.83
Message was edited by: FrankKulash
Sorry; I meant to reply to OP, not to Greg -
To fetch all active records in Report falling in the Date Range
Gurus,
My requirement goes like this. In my Bex Report I have Input prompt on ZStart_Date [ Interval Mandatory ] type.
There is something called as process which can have start Date and End Date.
Say
Process A has Start Date as 01.01.1990 End Date - 31.12.9999 ( ie., ongoing)
Process B has Start Date as 01.01.1995 End Date - 01.01.2000 ( i.e., Process Dead)
So when I execute the report giving the prompt for Start Date as 01.01.2008 to 31.12.2008, the report should fetch me all active processes which falls in that period regardless of the process start date at the same time it should not consider Dead Processes.
To help you guys, I have got a logic of using a customer exits variable or sort of this, but I dont know much about these concepts.
Any pointers would be og GREATEST help.
Regards,
YaseenShalabh,
To be precise enough , We term a process ongoing based on the End Date of Process.
Say, process X can started on 01.01.2000 and Ended on 31.12.2005, so when I execute the report say for period 01.01.2006 - 31.12.2006 , Process X is Dead according to reporting Period and hence should not appear in the report.
The report should fetch process which are ongoing i.e., there end dates can be 31.12.9999 or can be between the reporting period.
couldnt understand "regardless of the process start date " .....??
mean , say Process A started on 01.01.1995 and End Date is 31.12.9999 ( which we term as ongoing ). So when my reporting period is say 01.01.2006 to 31.12.2006 I should fetch this process, and thats why I term this as Active process in the Reporting Period.
Hope this clarifies.
Edited by: Yaseen Ahmed on Dec 15, 2008 5:32 PM -
How to use SQL*LOADER to read data in |SMITH|ALFRED| format
the data I need to upload to table using SQL*LOADER is in format as below:
|AD |Argentina |
|CN |China |
|US |America |
|GB |England |so how should I write my control file to read the data into two columns table?
I googled and people say that use Enclosed fields—delimiter (|), and I tried with below, but not working:
LOAD DATA
INFILE *
insert
INTO TABLE tmp_country_mapping
FIELDS ENCLOSED BY '|'
(country_id, country_name)
BEGINDATA
|AD |Argentina |
|CN |China |
|US |America |
|GB |England |Anyone could help?
BTW, I don`t want the spaces behind the value of the second column.
Thanks
Edited by: PhoenixBai on Dec 28, 2010 2:50 PMProblem solved, by removing the NLS_LANG=ENGLISH.
>
before the load, data is as below:
|AD |安道尔共和国 |
|AE |阿联酋 |
|AF |阿富汗 |
|AG |安提瓜和巴布达 |
|AI |安圭拉岛 |
|AL |阿尔巴尼亚 |after the load, data displays as below:
AD °2μà??12oí1ú
AE °¢áa??
AF °¢??o1
AG °2ìá1?oí°í2?′?
AI °21?à-μo
AL °¢??°í?á??And my database supports Chinese words and it displays correctly for other tables, except this one.
What could be the problem?
>
Edited by: PhoenixBai on Dec 28, 2010 5:05 PM -
Hi ,
How to use SQL Tracer..(ST05).
Thanks,
SubbuHi,
ST05: SQL trace
1.create a small ABAP/4 program that contains only the select statement. Before proceeding, test it to ensure that it works.
2.Open that program in the editor so that it is ready and waiting to execute.
3.Open a new session using the menu path System->Create session.
4.Run transaction ST05 (enter /nst05-zero-five, not oh-five-in the Command field, or choose the menu path System->Utilities->SQL Trace). The Trace SQL Database Requests screen is displayed.
5.If the Trace SQL Status Information box reads Trace SQL is switched off, go to step 7.
6.At this point, the Trace SQL Status Information box contains Trace SQL switched on by, followed by the user id who turned on the trace and the date and time it was started. You must switch it off before you can proceed. If the trace was started within the past hour, it is possible that it is still being used. Contact the indicated user or try again later. If the trace was started hours or days ago, the user probably left it on by mistake and it can be safely turned off. To turn off the trace, press the Trace Off pushbutton. The message in the Trace SQL Status Information box should now read Trace SQL is switched off.
7.Press the Trace On pushbutton. The Trace SQL Database Requests dialog box is displayed. The DB-Trace for User field should contain your user ID. If your user ID is not in this field, enter it now.
8.Press the OK button. You are returned to the Trace SQL Database Requests screen and the status information reads Trace SQL switched on by, indicating that you turned on the trace.
9.Switch back to the window containing your editor session (the one with your program waiting to execute).
10.Press F8 to run your program. (Only press F8, do not do anything else, do not even press the Back button.)
11.When your program has run and the hourglass is no longer displayed, switch back to the trace window.
12.Press the Trace Off pushbutton. The status information reads Trace SQL is switched off.
13.Press the List Trace pushbutton. The Trace SQL Database Requests dialog box is displayed. The fields on this screen will already contain values.
14.Press the OK button. You might need to wait a little while, at most a couple of minutes. The Trace SQL: List Database Requests screen is displayed.
15.Type %sc in the Command field and press the Enter key. The Find dialog box is displayed.
16.Type the name of the table you are tracing in the Search For field. (This is the table named in the select statement in your ABAP/4 program.)
17.Press the Find button. A search results list should be displayed with your table name highlighted.
18.Click on the first highlighted table name. You are returned to the Trace SQL: List Database Requests screen. Your cursor is positioned on the first line containing your table name. To the right of it, in the Operation column, should be the word PREPARE, OPEN, or REOPEN.
19.Press the Explain SQL button on the Application toolbar. The Show Execution Plan for SQL Statement screen is displayed.
20.Scroll down to the execution plan. The index used will be displayed in blue.
Jogdand M B -
How to use sql query in java ?
i don't know how to use sql query in java code.
who can give me some advice?
thankshttp://java.sun.com/developer/onlineTraining/Database/JDBC20Intro/
-
How to use SQL functions in the queries
hey guys i wanna know how to use SQL functions in the queries is it possible or not .
Hi,
Wat exactly that set values are?
those from sql query?
How to use count():
The COUNT() function returns the number of rows that matches a specified criteria.
SQL COUNT(column_name) Syntax
The COUNT(column_name) function returns the number of values (NULL values will not be counted) of the specified column:
SELECT COUNT(column_name) FROM table_name
SQL COUNT(*) Syntax
The COUNT(*) function returns the number of records in a table:
SELECT COUNT(*) FROM table_name
SQL COUNT(DISTINCT column_name) Syntax
The COUNT(DISTINCT column_name) function returns the number of distinct values of the specified column:
SELECT COUNT(DISTINCT column_name) FROM table_name
The IN function helps reduce the need to use multiple OR conditions.
The syntax for the IN function is:
SELECT columns
FROM tables
WHERE column1 in (value1, value2, .... value_n); -
how to use dual monitor display in windows 7 using MSTSC command ....?????
Hi Anurag,
The main issue is how to use the dual monitor in the Remote Desktop Session in Windows 7 ,right ?
please refer to the following links:
Using Multiple Monitors in Remote Desktop Session
http://blogs.msdn.com/b/rds/archive/2009/07/01/using-multiple-monitors-in-remote-desktop-session.aspx
Best regards -
How to Use SQL Query having IN Clause With DB Adapter
Hi,
I am using 11.1.1.5 want to find out how to Use SQL Query having IN Clause With DB Adapter. I want to pass the IN values dynamically. Any ideas.
Thanksinvoke a stored procedure, it's safer than trying to put together an arbitrary SQL statement in the JCA adapter
-
How to use Sql Loader in Unix Environmant
Hi All,
Can anyone explain me please how to use sql Loader in unix environment.
Actually i have one control file i want to run that file in Unix how can i achive please explain me
Thank'sHi Kuljeet,
Thank you for your replay
I just put my control file into the Unix Environmant that's fime
and when i trying to entering the following cmd in Unix environment i am getting this error
sqlldr username/password@string control='unix_pathname'i am not sure about the path name my question is
1) Do i need to give the Local file Path Or Unix Path
This is the error in Sql Loader:
SQL*Loader: Release 10.2.0.4.0 - Production on Mon Sep 24 13:14:23 2012
Copyright (c) 1982, 2007, Oracle. All rights reserved.
SQL*Loader-500: Unable to open file (/bx167a/riskbatch/rdwdbat/sample_upl.upl)
SQL*Loader-553: file not found
SQL*Loader-509: System error: No such file or directory
Could you please correct me
Thank's -
How to use SQL() function while writing scripts in BODS 4.0
How to use SQL() function while writing scripts in BODS 4.0
Hello,
I think you want to post your question to the [Data Integration and Data Quality Management|Data Services and Data Quality; forum. This forum is for other BusinessObjects SDK development questions.
Sincerely,
Dan Kelleher -
How to use SQL Developer Debugger
I'm using SQL Developer Version 3.2.20.09 and want to use its debugger option. I tried to get "how to use SQL Developer Debugger" by using google.ca but didn't get any tutorial. I really appreciate if someone suggest me any good and simple tutorial regarding SQL Developer Debugger, Thanks in advance.
Hello,
you can find a tutorial here:
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/devdays2012/mod2_sqldev/mod2_sqldev.html
Joop -
how to use ni-6008 and build a four channel data acquisition at a rate of 250 samples per channel and display all the data in a waveform chart
Hi kdm,
please stick in one thread for the same topic!
Best regards,
GerdW
CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
Kudos are welcome -
How to use Sql data source from Essbase 9.3.1
Hi All,
How to use Sql data source from Essbase 9.3.1 for ASO cube.Are there any rules and limitations for that.
Do we need to create any data source connection for this purpose. If there please let me know the dteps to create that connection.
RegardsYes you need to create one DSN connection and you have to use DSN name and login details at the time of building/loading of the outline.
Create DSN
Goto Administrative tools -> DataSources (ODBC) and add the DSN name and specify the Server name of SQL and login details and database.
goto data prep editor and click on File Menu and Click on Open SQL option Next window opens.
There you have to enter the details of the DSN connection and SQL query to build/load.
Thanks,
Prathap -
I know nothing about how to use my new ipod and when reading the little information that came with it, all I can do is turn it on. Then in a few seconds it goes black, never having brought up a screen to do anything! Help! What do I do to get this thing going?
You might consider connecting it to the charger and charging up the battery overnight.
Please Get the iPod Touch User Manual for iOS 5
Maybe you are looking for
-
Freight from PO or goods receipt into sales order in Third party drop ship
Hello!!! We have a requirement where the freight charged by vendor in third party drop ship sales order scenario should show up in the billing document to customer. So we will create a sales order with TAS item category. This will create PReq and PO
-
Takes a long time to find wireless network
So for the past few months my (Santa Rosa) MBP will take an extremely long time to find a wireless network. This happens both at home and other places where I have connected in the past and am wanting to use a remembered network. It can take as long
-
Apple TV Losing Computer Library
I have an iMac with iTunes Library and Home Sharing. iTunes and OS X are both on the latest versions. I use an ATV3 in the living room to stream movies, photos, music. Since the latest iTunes update, I have at least one issue per day where the ATV
-
Hi, I am a newbie with AL BPM, and am trying to use it for a project. We are trying to manage breaks for incoming events. An event could have multiple breaks associated with it and would be assigned to a user to resolve. One of the key requirements i
-
please suggest a good topic on project on interaction of java and c for my final year mca curriculum project.