SQL Query for Date field updation
I want a query from u.. Hope u help me with a
solution soon..
My Q: I want to update a date field in Oracle
database. But the condition is that i shouldnt change
the hours, minutes & seconds of the date field.
generally , if we update the date field then it takes
the default values for hours, min's & sec's to
00:00:00.
EX : if we have a value 21-SEP-2002 04:54:44 in a date
field. I want to update it to 22-SEP-2002 04:54:44.
But it updates to 22-sep-2002 00:00:00 if we use
UPDATE command.
Use a PreparedStatement:
PreparedStatement ps = conn.prepareStatement("SELECT * FROM TEMP WHERE TDATE > ? AND TDATE < ?");
// note: month numbers start at 0, so 1 is february
GregorianCalendar c1 = new GregorianCalendar(2002, 1, 11, 11, 0);
GregorianCalendar c2 = new GregorianCalendar(2002, 1, 18, 22, 0);
Date d1 = c1.getTime();
Date d2 = c2.getTime();
java.sql.Timestamp sqlDate1 = new java.sql.Timestamp(d1.getTime());
java.sql.Timestamp sqlDate2 = new java.sql.Timestamp(d2.getTime());
ps.setTimestamp(1, sqlDate1);
ps.setTimestamp(2, sqlDate2);
ResultSet rs = ps.executeQuery();
// get results from the result setJesper
Similar Messages
-
On a reports page there are two 2 date picker items ( a datefrom and a dateto) along with a text field with autocomplete item
When the page loads the following query is called
SELECT
"COL1",
"COL2",
"COL3",
from "TABLE"
WHERE MYDATES BETWEEN :DATEFROM AND :DATETO
Which returns no records as no dates have been selected.
How can I alter this so the WHERE clause on the date item searches is called only if and when the dates are chosen, and by default all records are shown.
The other related issue is when I have selected a from and to date and search when I go back into the report view page after viewing other pages in the apex app, the form fields are still populated, how can I clear the session down for these fields when the user leaves the page?
Hope this all makes sense?To_date('01.01.2100', 'dd.mm.yyyy') is going to give wrong results on 02.01.2100 :D
A solution (maybe there is a cleaner one...) :
WHERE
((:DATEFROM IS NOT NULL AND mydates >= :DATEFROM) OR :DATEFROM IS NULL)
AND
((:DATETO IS NOT NULL AND mydates <= :DATETO) OR :DATETO IS NULL)You can change the "No data found" message by modifiying the "When No Data Found Message" report attribute.
EDIT : And for the 2nd issue, Alex is right, but also be aware that Firefox retains form element values on page refresh, you have to switch the "Form Auto Complete" page security attribute to "Off" if you don't want to retain form element values.
Edited by: Yann39 on 27 juin 2012 06:30 -
SQL query for date & time interval
Hello everyone,
there is my problem
I have to make a search for events that are taking place during inserted date & time .
There's the table structure:
event
datefrom
dateto
timefrom
timeto
The problem is, when I try:
select * from xyz where datefrom <= inserted_date and dateto >= inserted_date and timefrom <= inserted_time and timeto >= inserted time;
then I don't get back all records.
eg: user inserts date = 10.10.2010 and time 10:00 and in the table is event [abc 11:00 9.10.2010 -> 09:00 11.10.2010] stored following way:
event abdc
datefrom 09.10.2010
dateto 11.10.2010
timefrom 11:00
timeto 09:00
=> this event won't be found, because the sql logic compares only single parameters and not their context.
Do you have any idea, how to solve this issue?
Thank you.
LukasHello Hubert,
thank you very much for your proposal, but your code makes the same select as mine (but in a more user friendly look :).
Table:
datefrom 09.10.2010
dateto 11.10.2010
timefrom 11:00
timeto 09:00
Event date = 10.10.2010 and time 10:00.
Your query:
select * from xyz where 10.10.2010 between 09.10.2010 and 11.10.2010 (that's so far ok) and 10:00 between 11:00 and 9:00 (no return there, because 10:00 doesn't lie within interval 11:00 -> 9:00... actually no value lies there) ;
Don't you have any other idea?
Thank you
Lukas -
In my Jsp program, i have 3 schemes, one for 1 month, second for 3 month, and third for 12 month.
Now an user can create his account and select any of the 3 schemes, what i want is that in my database table there are two columns one is tha startdate colume which holds data for the date posted, ie, current date, and the other column is the enddate which holds data for the expiry date depending on the schemes selected....
What i want is that when a user register for an account his startdate is the present date and i want a query which automatically calculates the enddate keeping in mind the scheme and update the table with the derived result.
Thanx :banghead:Check out the Calendar API, specially the add method, e.g, for adding 3 days to some date
Calendar cal = Calendar.getInstance();
cal.setTime(currentTime);//The current time
cal.add(Calendar.DATE, 3);//Add 3 days to the current timeCheck the api for adding months instead of days,
regards,
Manuel Leiria -
Hi All,
I have a table containing data like this
Person_name Time_spent Date/time
ABC 5.5 16-sep-10 12:00
ABC 3 16-sep-10 05:30
ABC 2.5 17-sep-10 12:00
ABC .5 16-sep-10 09:00
What I want is to get data like this
Person_name Time_spent Date/time
ABC 9 16-sep-10
ABC 2.5 17-sep-10
what query i should run?
Thanx
Omya query like this ...
select sum(time_spent), person_name, trunc(date_time) from <table_name>
group by person_name, trunc(date_time);
HTH. -
Hi,
I want to use the SQL query IF EXIST to update or insert data in a ms access table, but it doesn´t work
(fault number -2147217900)
I want to search for a value in a ms access table , if it exist i want to update it, if not i want to insert a new row.
Working with LabView 7.1, database con. toolset.
Who can HELP?
Thanks a lot
MarcoHello,
I think that If exist is not a standar SQL command (I know it exists I think in Oracle and SQL server), MS access doesn't support it, so I think the best way to do it is first make a Select and then either an Update or an insert, sorry...
Paulo -
Form on SQL query for updating.
Hello again,
Im trying to wirte a form to udapte the information in a table. I have a table with a PK which holds a persons name, and an activity assigned to them (and loads of other fields but they dont matter atm). I would like to have a form which has an SQL query running in one region and then the form underneath to be able to edit (reassign a person to a different activity) an item appearing in the query result. Ive got a form at the moment which is form on an sql query but its not updating when i fill out the form, is it something to do with the regions?
http://img.photobucket.com/albums/v611/Funky_Monk/untitled.jpg
So on the screenie, i have the bottom region for the query (no values in table hence the error (i think!))
The call ID is FK to another table
severity level and status will be usdated here
description is self-explanitory
analyst_id is the main field to be changed here, the call id will be assigned a new analyst via this form.
action_id is actions carried out on this problem.
Any help would be greatly appreciated.
DMhi,
Can you put this example on apex.oracle.com?
Regards,
Kartik Patel
http://patelkartik.blogspot.com/
http://apex.oracle.com/pls/apex/f?p=9904351712:1 -
Problem writing a sql query for a select list based on a static LOV
Hi,
I have the following table...
VALIDATIONS
ID Number (PK)
APP_ID Number
REQUESTED Date
APPROVED Date
VALID_TIL Date
DEPT_ID Number (FK)
I have a search form with the following field item variables...
P11_DEPT_ID (select list based on dynamic LOV from depts table)
P11_VALID (select list based on static Yes/No LOV)
A report on the columns of the Validations table is shown based on the values in the search form. So far, my sql query for the report is...
SELECT v.APP_ID,
v.REQUESTED,
v.APPROVED,
v.VALID_TIL,
d.DEPT
FROM DEPTS d, VALIDATIONS v
WHERE d.DEPT_ID = v.DEPT_ID(+)
AND (d.DEPT_ID = :P11_DEPT_ID OR :P11_DEPT_ID = -1)
This query works so far. My problem is that I don't know how to do a search based on the P11_VALID item - if 'yes' is selected, then the VALID_TIL date is still valid. If 'no' is selected then the VALID_TIL date has passed.
Can anyone help me to extend my query to include this situation?
Thanks.Hello !
Let's have a look at my example:create table test
id number
,valid_til date
insert into test values( 1, sysdate-3 );
insert into test values( 2, sysdate-2 );
insert into test values( 3, sysdate-1 );
insert into test values( 4, sysdate );
insert into test values( 5, sysdate+1 );
insert into test values( 6, sysdate+2 );
commit;
select * from test;
def til=yes
select *
from test
where decode(sign(trunc(valid_til)-trunc(sysdate)),1,1,0,1,-1)
=decode('&til','yes',1,-1);
def til=no
select *
from test
where decode(sign(trunc(valid_til)-trunc(sysdate)),1,1,0,1,-1)
=decode('&til','yes',1,-1);
drop table test; It's working fine, I've tested it.
The above changes to my first idea I did because of time portion of the DATE datatype in Oracle and therefore the wrong result for today.
For understandings:
1.) TRUNC removes the time part of DATE
2.) The difference of to date-values is the number of days between.
3.) SIGN is the mathematical function and gives -1,0 or +1 according to an negative, zero or positiv argument.
4.) DECODE is like an IF.
Inspect your LOV for the returning values. According to my example they shoul be 'yes' and 'no'. If your values are different, you may have to modify the DECODE.
Good luck,
Heinz -
How to set a date range for date field ?
Dear Experts,
Scenario:
I have a query in validating the date field in my BSP application. My application is for maintain infotype 0023 Other/Previous Employers online by employees in the company.
As per our design we are maintaining the all employment details of the employee both ( with in the current company / previous employment outside the company) in the same infotype.
Every employee will have a hiring date within the SAP HR system. We consider this date as the cutoff date between current and previous employment in our application. When the employee updating the details wia BSP page I need to check the following.
Record inside current company: Validation that, the user should only able to enter BEGIN DATE (BEGDA) greater than or equal HIRING DATE and END DATE(ENDDA) should be greater than FROM DATE (BEGDA).
Record outside current Company: Validation that, the user should only able to enter BEGIN DATE (BEGDA) less than or equal HIRING DATE and END DATE (ENDDA) should be greater than FROM DATE (BEGDA) and less than HIRING DATE.
Technical Requirement:
How to set a date range for date field, i.e. how we can limit the date range in a HTMLB date field? Can this it be achieved via standard functionality of HTMLB?
Following is the code to describe date field in my application.
<htmlb:inputField id= "ENDDA_NEW_IN"
type= "date"
doValidate= "TRUE"
showHelp= "TRUE"
disabled= "FALSE"
width= "183"
style= "cssTextAreadate"
value= "<%='99991231'%>"/>
Thanks a lot in advance for your assistance and help.
Cibinu2026
Edited by: cibin kuruvilla on Nov 12, 2008 11:13 AMHi,
This functionality is known to be very important and is a key part of the next major release of the JRC planned for the first half of 2008.
Regards,
<p>Blair Wheadon</p>
<p>Product Manager, Crystal Reports</p> -
BI UDI data load conflict using MS SQL Server and date fields
Hi BW Experts!
We have found some unexpected problems when we are trying to perform a data extraction process from an SQL database (non-SAP application).
We are using the BI UDI tool (JDBC Driver/Connector). The basic data extraction works properly, however we have some specific problems to work with SQL Server fields defined as Date Time.
The JDBC driver automatically intermediate the communication and translate these fields splitting the original SQL date time field into two separated fields with suffix _D (for date) and _T (for time).
It works perfect for extraction, but it doesnt work well when we try to restrict the data selection based on these fields.
When we put a date selection into the infopackage data selection area (we already have tried several date formats), the system simply ignores these selection parameters and send a SQL statement without WHERE clause to DBMS.
Please, anybody has experienced anything like this or know somethings that could help us?
This is a standard limitation from SAP BI UDI?
Thanks in advance and best regards,Hi Matt and Thomas
Many thanks for your replies.
Yes I have to do the join. Even worse I have to write an Aggregate query like this!
Select o.F1,o.F2, m.F1,m.F2, count(*)
from
table@oracleServer o,
table@microsoftSQLServer m
where o.F1=m.F1
group by o.F1,o.F2, m.F1,m.F2;
These are 2 different systems (hardware & software) which actually do the same job, they produce transactions for a common business entity. Kind of, both sell tickets for the same ABC ferry company.
I can not put them side by side on the dashboard, as I need to aggregate the data and present it maybe in a Oracle BI Report for Accounting and Financial reconciliation purposes.
The truth is, as it is. I can't change it, is too late.
I have to device a way to harvest both systems as they are. I don't want to move around data. I thought looking at Oracle BI I could write SQL against multiple Data Sources. I am struggling to find a way. As it seems that it can "SQL query" 1 data source at a time.
I have been hinted on another forum (OracleTURK) to use Oracle Transparent Gateways and Generic Connectivity. http://download.oracle.com/docs/cd/B19306_01/server.102/b14232/toc.htm
Shame, I have to pay licenses for OWB and Oracle Transparent Gateways. I thought DB vendors can do better. Why do I have to pay to access the other 50% of the market.
I can understand the performance implications this might have. Because of it I might even be forced at the end to move data (ETL) into a separate database, slice it into partitions and manage it that way. Pitty because currenlty I only need one report out of these systems but seems like will be dear to get.
Thank you for all your help.
Kubilay -
Error while executing a sql query for select
HI All,
ORA-01652: unable to extend temp segment by 128 in tablespace PSTEMP i'm getting this error while i'm executing the sql query for selecting the data.I am having 44GB of temp space, while executing the below query my temp space is getting full, Expert please let us know how the issue can be resolved..
1. I dont want to increase the temp space
2. I need to tune the query, please provide your recomendations.
insert /*+APPEND*/ into CST_DSA.HIERARCHY_MISMATCHES
(REPORT_NUM,REPORT_TYPE,REPORT_DESC,GAP,CARRIED_ITEMS,CARRIED_ITEM_TYPE,NO_OF_ROUTE_OF_CARRIED_ITEM,CARRIED_ITEM_ROUTE_NO,CARRIER_ITEMS,CARRIER_ITEM_TYPE,CARRIED_ITEM_PROTECTION_TYPE,SOURCE_SYSTEM)
select
REPORTNUMBER,REPORTTYPE,REPORTDESCRIPTION ,NULL,
carried_items,carried_item_type,no_of_route_of_carried_item,carried_item_route_no,carrier_items,
carrier_item_type,carried_item_protection_type,'PACS'
from
(select distinct
c.REPORTNUMBER,c.REPORTTYPE,c.REPORTDESCRIPTION ,NULL,
a.carried_items,a.carried_item_type,a.no_of_route_of_carried_item,a.carried_item_route_no,a.carrier_items,
a.carrier_item_type,a.carried_item_protection_type,'PACS'
from CST_ASIR.HIERARCHY_asir a,CST_DSA.M_PB_CIRCUIT_ROUTING b ,CST_DSA.REPORT_METADATA c
where a.carrier_item_type in('Connection') and a.carried_item_type in('Service')
AND a.carrier_items=b.mux
and c.REPORTNUMBER=(case
when a.carrier_item_type in ('ServicePackage','Service','Connection') then 10
else 20
end)
and a.carrier_items not in (select carried_items from CST_ASIR.HIERARCHY_asir where carried_item_type in('Connection') ))A
where not exists
(select *
from CST_DSA.HIERARCHY_MISMATCHES B where
A.REPORTNUMBER=B.REPORT_NUM and
A.REPORTTYPE=B.REPORT_TYPE and
A.REPORTDESCRIPTION=B.REPORT_DESC and
A.CARRIED_ITEMS=B.CARRIED_ITEMS and
A.CARRIED_ITEM_TYPE=B.CARRIED_ITEM_TYPE and
A.NO_OF_ROUTE_OF_CARRIED_ITEM=B.NO_OF_ROUTE_OF_CARRIED_ITEM and
A.CARRIED_ITEM_ROUTE_NO=B.CARRIED_ITEM_ROUTE_NO and
A.CARRIER_ITEMS=B.CARRIER_ITEMS and
A.CARRIER_ITEM_TYPE=B.CARRIER_ITEM_TYPE and
A.CARRIED_ITEM_PROTECTION_TYPE=B.CARRIED_ITEM_PROTECTION_TYPE
AND B.SOURCE_SYSTEM='PACS'
Explain Plan
==========
Plan
INSERT STATEMENT ALL_ROWSCost: 129 Bytes: 1,103 Cardinality: 1
20 LOAD AS SELECT CST_DSA.HIERARCHY_MISMATCHES
19 PX COORDINATOR
18 PX SEND QC (RANDOM) PARALLEL_TO_SERIAL SYS.:TQ10002 :Q1002Cost: 129 Bytes: 1,103 Cardinality: 1
17 NESTED LOOPS PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 129 Bytes: 1,103 Cardinality: 1
15 HASH JOIN RIGHT ANTI NA PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 129 Bytes: 1,098 Cardinality: 1
4 PX RECEIVE PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 63 Bytes: 359,283 Cardinality: 15,621
3 PX SEND BROADCAST PARALLEL_TO_PARALLEL SYS.:TQ10001 :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621
2 PX BLOCK ITERATOR PARALLEL_COMBINED_WITH_CHILD :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621
1 MAT_VIEW ACCESS FULL MAT_VIEW PARALLEL_COMBINED_WITH_PARENT CST_ASIR.HIERARCHY :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621
14 NESTED LOOPS ANTI PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 65 Bytes: 40,256,600 Cardinality: 37,448
11 HASH JOIN PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 65 Bytes: 6,366,160 Cardinality: 37,448
8 BUFFER SORT PARALLEL_COMBINED_WITH_CHILD :Q1002
7 PX RECEIVE PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 1 Bytes: 214 Cardinality: 2
6 PX SEND BROADCAST PARALLEL_FROM_SERIAL SYS.:TQ10000 Cost: 1 Bytes: 214 Cardinality: 2
5 INDEX FULL SCAN INDEX CST_DSA.IDX$$_06EF0005 Cost: 1 Bytes: 214 Cardinality: 2
10 PX BLOCK ITERATOR PARALLEL_COMBINED_WITH_CHILD :Q1002Cost: 63 Bytes: 2,359,224 Cardinality: 37,448
9 MAT_VIEW ACCESS FULL MAT_VIEW PARALLEL_COMBINED_WITH_PARENT CST_ASIR.HIERARCHY :Q1002Cost: 63 Bytes: 2,359,224 Cardinality: 37,448
13 TABLE ACCESS BY INDEX ROWID TABLE PARALLEL_COMBINED_WITH_PARENT CST_DSA.HIERARCHY_MISMATCHES :Q1002Cost: 0 Bytes: 905 Cardinality: 1
12 INDEX RANGE SCAN INDEX PARALLEL_COMBINED_WITH_PARENT SYS.HIERARCHY_MISMATCHES_IDX3 :Q1002Cost: 0 Cardinality: 1
16 INDEX RANGE SCAN INDEX PARALLEL_COMBINED_WITH_PARENT CST_DSA.IDX$$_06EF0001 :Q1002Cost: 1 Bytes: 5 Cardinality: 1 -
SQL query generating data in SQL management studio but not in CUIC interface
Hello,
I'm working on a UCCE 9.0 system
I created SQL query for a report.
Whenever I run the query inside the SQL management studio, it works and generates data, but when I run it in the CUIC interface it works but generates nothing. As you can see in the below snapshot, it contains 209 records that are not being displayed.
Any help would be greatly apprciatedIs it a custom report ? Can you right click on your Custom Report and click on Edit Views. You need to check whether you have Grid Headers Listed.
Regards,
Senthil -
i have a interface there user can enter two dates . in my servlet program i am getting it as string by using request .get parameter. i wanan to know how to write sql query for selecting data from database with between clause
//for example you are getting the date format like 17-Jul-2006 as String
String strDate1 = "17-Jul-2006";//request.getParameter("date1");
String strSQL = "SELECT SYSDATE from dual
WHERE SYSDATE - 10 > to_date('"+date1 +"','dd-mm-yyyy')";
Hope this example will help you!!!
Regards,
AfTaB -
How to create sql query for item master with operator LIKE with variables?
hi all,
How to create sql query for item master with
operator LIKE(Contains,Start With,End With) with variables using query generator in SAP B1 ?
JeyakanthanHi Jeyakanthan,
here is an example (put the like statement into the where field)
SELECT T0.CardCode, T0.CardName FROM OITM T0 WHERE T0.CardName Like '%%test%%'
The %% sign is a wildcard. If you need start with write 'test%%' and otherwise ends with '%%test'. For contains you need '%%test%%'. You also could combinate this statements like 'test%%abc%%'. This means starts with test and contains abc.
Regards Steffen -
How to write sql query for counting pairs from below table??
Below is my SQL table structure.
user_id | Name | join_side | left_leg | right_leg | Parent_id
100001 Tinku Left 100002 100003 0
100002 Harish Left 100004 100005 100001
100003 Gorav Right 100006 100007 100001
100004 Prince Left 100008 NULL 100002
100005 Ajay Right NULL NULL 100002
100006 Simran Left NULL NULL 100003
100007 Raman Right NULL NULL 100003
100008 Vijay Left NULL NULL 100004
It is a binary table structure.. Every user has to add two per id under him, one is left_leg and second is right_leg... Parent_id is under which user current user is added.. Hope you will be understand..
I have to write sql query for counting pairs under id "100001". i know there will be important role of parent_id for counting pairs. * what is pair( suppose if any user contains both left_leg and right_leg id, then it is called pair.)
I know there are three pairs under id "100001" :-
1. 100002 and 100003
2. 100004 and 100005
3. 100006 and 100007
100008 will not be counted as pair because it does not have right leg..
But i dont know how to write sql query for this... Any help will be appreciated... This is my college project... And tommorow is the last date of submission.... Hope anyone will help me...
Suppose i have to count pair for id '100002'. Then there is only one pair under id '100002'. i.e 100004 and 100005Sounds like this to me
DECLARE @ID int
SET @ID = 100001--your passed value
SELECT left_leg,right_leg
FROM table
WHERE (user_id = @ID
OR parent_id = @ID)
AND left_leg IS NOT NULL
AND right_leg IS NOT NULL
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
Maybe you are looking for
-
Updated firefox on xp all of a sudden it crashes with all these po ups
I had firefox on my desktop home for 3 years i hit the update button to go to 8.0 version ,it started to crash. re downloaded same problem confused
-
HI @, I am using a file adaptor which is reading the file and then archiving it after successfull reading .Now what happened that In my scenarion the file got picked up by adaptor and archived also but there is no trace available in the SXMB_MONI I n
-
UCCE 7.5.8 with CAD Agents sitting in India
Hi all, I've got a scenario and am looking for some inputs. I've got a centralized CUCM 7.1.3 with UCCE 7.5.8 and CAD 7.5.8. Today I only phones at our India office and all is working perfectly fine with no issues. I am looking into having CAD agents
-
Hi guys, My XI scenario is Idoc's to JDBC 2.0. The idoc´s reach the XI and i can see them with status Processed Successfully in SXMB_MONI. But when i double click in the message i see at pipeline´s step this: Inbound Message - green flag Scheduled R
-
My iPhone 4 and Microsoft Outlook 2010 suddenly stopped syncing calendars. Previously, there was an iCloud symbol on the calendar view in outlook and it has disappeared. I had changed no settings. The iPhone and iCloud are syncing OK. On the iPhone,