Receiving error when calculating two fields with different date format

I am more familiar with SQL Server than Oracle, so after searching online without success, I am asking here.
I'm using PL/SQL Developer with Oracle DB 11g Enterprise Release 11.2.0.2.0 64 Bit
MyTable:
ID_Number     VarChar2
Date_Received     Date
Select ID_Number,
     Date_Received,
     To_Date(substr(ID_Number, 1,6), 'YYMMDD') SentDate,    
     Date_Received - To_Date(substr(ID_Number, 1,6), 'YYMMDD') NumDays
From MyTable
Where substr(ID_Number, 7,3) in ('ABC', 'ABD')
and Length(Trim(Translate((substr(ID_Number, 1,6)), '0123456789', ' ' ))) is null
ID_Number                    Date_Received          SentDate          NumDays
131002ABC1654106     10/16/2013               10/2/2013          14
131004ABD8813899     4/12/2013                 4/8/2013            4
131014ABD1844832     10/16/2013               10/14/2013          2
Sometimes the first 6 characters in the ID_Number are not numbers, and the Length(Trim(Translate removes those records
I just want records where NumDays > 2
I've tried putting the query in a subquery and using Where NumDays > 2 outside.  I've also tried using the computation directly in the Where clause.  Without this in the Where clause it runs fine, with it in either spot I get the following error:
ORA-01931: Date format picture ends before converting entire input string
I'm not sure how to put both dates in the same format.  I've tried declaring the format to no avail.  I do not understand how I can calculate within the select but not use the same calculation within the Where clause.
Thank you for your help.

Hi,
SQL is a language for describing the results you want.  How the system gets those results is up to it; you don't have much say regarding which conditions will be applied when.
One place where you can control the order of things is in a CASE expression.  When you say
CASE
    WHEN  condition_1
    THEN  expression_1
END
you can be sure that expression_1 will only be evaluated when cond_1 is TRUE.
Try something like this:
WITH  got_sent_date AS
    SELECT  id_number, date_received
    ,       CASE
                WHEN  TRANSLATE ( SUBSTR (id_number, 1, 6)
                                , 'x 0123456789'
                                , 'x'
                                )  IS NULL
                THEN  TO_DATE ( SUBSTR (id_number, 1 6)
                              , 'YYMMDD'
            END     AS sent_date
    FROM    MyTable
    WHERE   SUBSTR (id_number, 7, 3) IN ('ABC', 'ABD')
SELECT  id_number
,       date_received
,       sent_date
,       date_received - sent_date    AS num_days
FROM    got_sent_date
WHERE   date_received  > sent_date + 2
If you'd care to post some sample data (CREATE TABLE and INSERT statements) and the results you want from that data, then I could test this.
Of course, you'll still have run-time errors if id_number starts with 6 digits, but they don't happen to be valid, e.g. '131100' or '130229'.  That's one of the many reasons why storing date information in VARCHAR2 columns is such a bad idea.  To get around that problem, see
https://forums.oracle.com/message/4255051

Similar Messages

  • How to compare two rows from two table with different data

    how to compare two rows from two table with different data
    e.g.
    Table 1
    ID   DESC
    1     aaa
    2     bbb
    3     ccc
    Table 2
    ID   DESC
    1     aaa
    2     xxx
    3     ccc
    Result
    2

    Create
    table tab1(ID
    int ,DE char(10))
    Create
    table tab2(ID
    int ,DE char(10))
    Insert
    into tab1 Values
    (1,'aaa')
    Insert
    into tab1  Values
    (2,'bbb')
    Insert
    into tab1 Values(3,'ccc')
    Insert
    into tab1 Values(4,'dfe')
    Insert
    into tab2 Values
    (1,'aaa')
    Insert
    into tab2  Values
    (2,'xx')
    Insert
    into tab2 Values(3,'ccc')
    Insert
    into tab2 Values(6,'wdr')
    SELECT 
    tab1.ID,tab2.ID
    As T2 from tab1
    FULL
    join tab2 on tab1.ID
    = tab2.ID  
    WHERE
    BINARY_CHECKSUM(tab1.ID,tab1.DE)
    <> BINARY_CHECKSUM(tab2.ID,tab2.DE)
    OR tab1.ID
    IS NULL
    OR 
    tab2.ID IS
    NULL
    ID column considered as a primary Key
    Apart from different record,Above query populate missing record in both tables.
    Result Set
    ID ID 
    2  2
    4 NULL
    NULL 6
    ganeshk

  • Receiving Error when running Crystal reports with Images in WebSphere 6.1

    I am designing a report with a sub report that displays images via (BLOBS). The images are between 10-20 kb in size and there could be up to 200 images in the report.
    There are no problems when I run the report using Java 1.5 with Tomcat 5.5 server and JDBC connection (using ojdbc14.jar) to an Oracle 10g database.
    It seems that if I attempt to run the same report on a WebSphere 6.1 environment, the below error is encountered (stack trace is below)
    I am using Crystal 2008 (ver 12.0.0.683).
    Based on the stack trace, I think it is either an IBM JDK  javax.* package compatibility issue or the current version of Crystal reports (no service packs installed - current client environment) has a known issue with Websphere.
    I searched the forums for any similiar issues but could not find one.
    Could installing Service pack 3 solve this issue or is there another possibility?  
    Any assistance would be greatly appreciated.
    Thank you.
    Tony. 
    Stack Trace follows  (Needed to trim due to size, trying to keep unique messges) *******
    ERROR [pool-14-thread-1] c.u.p.e.g.c.GenerateCrystalReport [GenerateCrystalReport.java : 211] Generate Report: Template =
    pusehk08\evm$\EVM REPORTS 5.7.2010\Staging\TEARDOWN_COM.rpt, ReportSDKException caught: javax/imageio/metadata/IIOMetadata.getAsTree(Ljava/lang/String;)Lorg/w3c/dom/Node;
    com.crystaldecisions.sdk.occa.report.lib.ReportSDKException: javax/imageio/metadata/IIOMetadata.getAsTree(Ljava/lang/String;)Lorg/w3c/dom/Node;
    at com.crystaldecisions.sdk.occa.report.application.PrintOutputController.if(SourceFile:237) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.crystaldecisions.sdk.occa.report.application.PrintOutputController.export(SourceFile:147) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.crystaldecisions.sdk.occa.report.application.PrintOutputController.export(SourceFile:128) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.crystaldecisions.sdk.occa.report.application.PrintOutputController.export(SourceFile:111) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.utc.pw.evm2.generatereports.crystalreports.GenerateCrystalReport.generateReport(GenerateCrystalReport.java:152) [classes/:na]
    at com.utc.pw.evm2.generatereports.ReportThread.run(ReportThread.java:144) [classes/:na]
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:678) [na:1.5.0]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:703) [na:1.5.0]
    at java.lang.Thread.run(Thread.java:811) [na:1.5.0]
    Caused by: java.lang.VerifyError: javax/imageio/metadata/IIOMetadata.getAsTree(Ljava/lang/String;)Lorg/w3c/dom/Node;
    at com.crystaldecisions.reports.common.image.ImageUtils.a(SourceFile:901) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.crystaldecisions.reports.common.image.ImageUtils.if(SourceFile:873) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.crystaldecisions.reports.common.JavaImage.do(SourceFile:183) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.crystaldecisions.reports.common.CrystalImage.createImage(SourceFile:50) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.crystaldecisions.reports.formatter.formatter.objectformatter.FormattedBlobFieldObject.if(SourceFile:103) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.crystaldecisions.reports.formatter.formatter.objectformatter.FormattedBlobFieldObject.<init>(SourceFile:57) [CrystalReportsRuntime.jar:12.2.207.916]
    [CrystalReportsRuntime.jar:12.2.207.916]
    at com.crystaldecisions.reports.formatter.formatter.paginator.PageFormatter.formatPage(SourceFile:236) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.crystaldecisions.reports.formatter.export2.a.a(SourceFile:96) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.crystaldecisions.reports.formatter.export2.a.a(SourceFile:247) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.crystaldecisions.reports.formatter.export2.ExportSupervisorEx.if(SourceFile:642) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.crystaldecisions.reports.formatter.export2.ExportSupervisorEx.a(SourceFile:586) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.businessobjects.reports.sdk.requesthandler.ReportViewingRequestHandler.a(SourceFile:636) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.businessobjects.reports.sdk.requesthandler.ReportViewingRequestHandler.int(SourceFile:672) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.businessobjects.reports.sdk.JRCCommunicationAdapter.do(SourceFile:1944) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.businessobjects.reports.sdk.JRCCommunicationAdapter.if(SourceFile:661) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.businessobjects.reports.sdk.JRCCommunicationAdapter.a(SourceFile:167) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.businessobjects.reports.sdk.JRCCommunicationAdapter$2.a(SourceFile:529) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.businessobjects.reports.sdk.JRCCommunicationAdapter$2.call(SourceFile:527) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.crystaldecisions.reports.common.ThreadGuard.syncExecute(SourceFile:102) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.businessobjects.reports.sdk.JRCCommunicationAdapter.for(SourceFile:525) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.businessobjects.reports.sdk.JRCCommunicationAdapter.int(SourceFile:424) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.businessobjects.reports.sdk.JRCCommunicationAdapter.request(SourceFile:352) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.businessobjects.sdk.erom.jrc.a.a(SourceFile:54) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.businessobjects.sdk.erom.jrc.a.execute(SourceFile:67) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.crystaldecisions.proxy.remoteagent.RemoteAgent$a.execute(SourceFile:716) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.crystaldecisions.proxy.remoteagent.CommunicationChannel.a(SourceFile:125) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.crystaldecisions.proxy.remoteagent.RemoteAgent.a(SourceFile:537) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.crystaldecisions.sdk.occa.report.application.ds.a(SourceFile:186) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.crystaldecisions.sdk.occa.report.application.ReportSource.a(SourceFile:1558) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.crystaldecisions.sdk.occa.report.application.ReportSource.a(SourceFile:337) [CrystalReportsRuntime.jar:12.2.207.916]
    at com.crystaldecisions.sdk.occa.report.application.PrintOutputController.if(SourceFile:223) [CrystalReportsRuntime.jar:12.2.207.916]
    ... 8 common frames omitted
    2010-07-20 15:57:11,147 ERROR [pool-14-thread-1] c.u.p.e.g.ReportThread [ReportThread.java : 233] Attempt to generate report TEARDOWN using
    pusehk08\evm$\EVM REPORTS 5.7.2010\Staging\TEARDOWN_COM.rpt for E733570-01 failed: Generate Report: Template =
    pusehk08\evm$\EVM REPORTS 5.7.2010\Staging\TEARDOWN_COM.rpt, ReportSDKException caught: javax/imageio/metadata/IIOMetadata.getAsTree(Ljava/lang/String;)Lorg/w3c/dom/Node;, REPORTSDKEXCEPTION
    2010-07-20 15:57:11,147 ERROR [pool-14-thread-1] c.u.p.e.g.ReportThread [ReportThread.java : 238] Exception was caught trying to build report:
    com.crystaldecisions.sdk.occa.report.lib.ReportSDKException: javax/imageio/metadata/IIOMetadata.getAsTree(Ljava/lang/String;)Lorg/w3c/dom/Node;
    Edited by: Liro9999 on Jul 21, 2010 1:55 PM

    Thank you for your reply.
    The answer to your question concerning if Websphere is a clean install is no.  The client has other applications running on that server.  We do not have access to that server other than the log files and I requested information as to what other applications are on the server.
    We did try adding a known working version of the IIOMetadata class in the ear file and deploying it in the hopes that  class will be loaded before using any other version.  Unfortunately, we receive the posted errors.  Which may mean that a different version of the class has already been loaded in memory and that is the one being accessed.  A request would have to be made to the client for a shutdown and restart of Websphere in determining if that may be the case.  Since there are other applications running, coordination and communication to the other application owner will need to be done first.
    Any additional ideas will be appreciated.
    Thank you.
    Tony.

  • Received error when i tried to add a data source to index

    I received an error message when tried to add a data source to the index. The data source is a File system repository.
    Error:
    The repository needs the properties service to be attached to a classification index.
    Your help is greatly appreciate!

    Hi guys,
    Thanks so much for a quick response.
    Are you talking about these services below? if yes, I had already add them to the FS.
    properties
    RepositoryAttachmentService
    subscription
    svc_acl
    Thanks again,

  • Search help for custome field with different data type

    Hi Friends,
    I have Created a  custom table in which i have created a field is
    ZMATLONG which stores material number.
    Now the data element is zdmat which is of char 40..
    Now i want to give search help for this field ZMATLONG..
    I have tried many ways giving search help to this field
    a) i Tried to attach the standard search help of MATNR ie : MAT1 but its showing me data type inconsistancy
    b) i created a zsearch help and in the selection method i have used database table mara , again here iam getting the same error data type inconsistancy...
    Now how can i give the search help like matnr field to my custom field ZMATLONG...
    How can i do it..?
    Thanks in Advance..
    Regards
    Kumar

    Hi,
    MATNR ahs length 18 and ZMATLONG has length 40.So due to this u cannot use MAT1 search help.
    best way would be cope MAT1 into Z search help. Then in the search help parameter change the data element of field
    MATNR as ZMATLONG.
    Now if you assign Z search help to ZMATLONG  it will work.
    I tried this its working fine.
    Shanmugavel Chandrasekaran

  • Two charts with different data on single report

    Hi there,
    I've a requirement to report on two weeks, past week and current week. The data is grouped by a type.The report should  display separate charts side by side, one chart for the past week and the other for the current week, for comparision purposes. The details can display the data together for the two weeks.
    Is it possible to select data on charts?
    I'm using Crystal Reports for Visual Studio 2005.
    Any help is highly appreciated.
    Thanks,
    Seshu

    Insert two subreports and create the charts in them.

  • Date comparision issue with different date formats

    Hi Friends
    I am trying to find difference in hours between two dates but not able to do that as the formats of both dates that i have are different.
    But i have both the dates in the String format. belwo is my code.
    First Date is in the format - yyyy-MM-dd-HH.mm.ss.SSS. String sDate = "2011-05-29-13.50.44.050761";
    Secong date is in the format - yyyy-MM-dd HH.mm.ss String uiDate = "2011-05-29 13.50.44";
    Now i need to parse both the Strings into a Date object and format that so that i can subtract both dates using the
    long difference = uiDate .getTime() - sDate.getTime();
    Can you please let me know how i can do that as the format of both the dates are different.
    Is there a way like a common format to which these both can be converted and calculation done.
    any suggestions and solutions would be of great help.

    Thanks All for your suggestions
    well i figured out the solution with some goggling and r&d.
    For the first case I was getting the Date and Time fields from the UI as two different fields. I then combined these into a Date object and set the format for the first date as yyyy-MM-dd-HH.mm.ss.SSS.
    The second date was already in the above format. Then the i just did the Date comparison and got the difference in hours which was what i wanted.
    Vikeng

  • URGENT: XML-SQL: Error parsing different date formats in the same XML file.

    Hi Everyone,
    I have a big problem while using the XML-SQL utility. I have a XML file with different date formats. I get exception like the one below.
    "oracle.xml.sql.OracleXMLSQLException: 'java.text.ParseException: Unparseable date:"
    And the XML file is :
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Info Key="ID">
         <Insert>
              <ID>1</ID>
              <BookingDate>10.12.2001</BookingDate>
              <OpeningTime>19:16</OpeningTime>
         </Insert>
    </Info>
    I have tried using different setDateFormat which is contrary.
    sav.setDateFormat("d.M.y");
    sav.setDateFormat("H:m:s");
    Can someone help me on the same.
    Thanks in advance.
    Subramanian.

    You might have to describe the columns as varchar then modify the table to the right format.

  • I have my ipad notes linked to gmail and suddenly disappeared when I put the sim card into a new iphone, the funny thing is that almost all disappeared except 4 and with different dates up to two years. Why did this happen? No way to recover them?

    I have my ipad notes linked to gmail and suddenly disappeared when I put the sim card into a new iphone, the funny thing is that almost all disappeared except 4 and with different dates up to two years. Why did this happen? No way to recover them?

    Wow, Karan Taneja, you've just embarrassed yourself on a worldwide support forum.  Not only is your post ridiculous and completely inappropriate for a technical support forum, but it also shows your ignorance as to whom you think the audience is.  Apple is not here.  It's users, like you. 
    If you would have spent half the time actually reading the Terms of Use of this forum that YOU agreed to by signing up to post, as you did composing that usesless, inappropriate post, you (and the rest of us on this forum) would have been much better off.

  • How can I have two fields with the same name if it makes sense?

    Hello, folks :)
    I have a pretty hard time figuring out how I can have two text fields with the same binding name.
    The whole problem is that when I need two fields with the same binding name they are still differnent coz they have the same name but differnt indices.
    I should make a form filled at runtime by merging a pdf form file and an fdf file data file. And I have no choice to do it differently. And my form file needs some data like customerName, companyName twice in one form. But there's only one possible buinding name indexed zero.
    How can I create a field with absolutely the same name or is it just impossible due to possible name conflicts? And is there a workaround to this problem? I just need one piece of data repeated in different places.
    Thanks for your replies :)
    P.S. if u think that the problem is not clear enough let me know. I'll supply you with more details. But the general process can not be changed.
    One pdf should be mergred with an fdf with as the result of their merge a new filled and flattened form. I have no control over fdfs their are generated by Oracle and I can not fill the form using XML files coz this process should be integrated in a working application.

    I just thought about a really ugly workaround with a server-side script adding values to fdf files but it's a bit of work and tests and personally i think it's a bad idea :-(

  • Receive error when starting iTunes

    Receive error when starting iTunes "The registry settings used by the iTunes drivers for importing and burning CDs and DVDs are missing. This can happen as a result of installing other CD burning software. Please reinstall iTunes" I have with no success.

    I'd start with the following document, with one modification. At step 12 after typing GEARAspiWDM press the Enter/Return key once prior to clicking OK. (Pressing Return adds a carriage return in the field and is important.)
    iTunes for Windows: "Registry settings" warning when opening iTunes

  • Keep receiving error when trying to change device on my verizon.  Unfortunately, none of the lines on your account are eligible to receive the Online Authorization Code

    Keep receiving error when trying to change device on my verizon.  Unfortunately, none of the lines on your account are eligible to receive the Online Authorization Code. 
    Unable to change device on account.

    That would be great if they weren't 2 different size SIM cards.
    The code is a security feature and I realize this. It is to prevent someone from hacking your account and changing your devices without your knowledge. However, I am the account owner and I know exactly what is going on with my account at all times. I check data usage AT LEAST 2 times daily and I log into my account at least once daily. I would very quickly discover any issues. This feature is more of a (removed)
    Edited as required by the Verizon Wireless Terms of Service
    Message was edited by: Admin Moderator

  • How to combine two applications with different workspaces in APEX

    Hi,
    Can anyone help out in merging two applications with different workspaces in APEX 3.2 ?
    Thanks in advance,

    Hello Satya,
    >> I am Satya …
    Please take one more step to help us and update your forum handle to something friendlier than user123… Thanks.
    >> Can anyone help out in merging two applications with different workspaces in APEX 3.2 ?
    This is not a trivial task.
    You didn’t mentioned if both workspaces sharing the same APEX instance, or they are on two different instances (machines). I believe the latter is a pre-condition to a success.
    First you need to remember that importing an APEX component, like a single page, is possible only to the same application that it was exported from. This is still valid if you have the same workspace on two separate APEX instances – one is an import of the other (which makes it an identical copy). Still, the application ID must be the same, or you’ll get the following error: “This page was exported from a different application or from an application in different workspace. Page cannot be installed in this application.”
    You can’t simply manipulating the export file, if the two workspaces are sharing the same APEX instance, as all workspaces on the same instance shares the same APEX metadata files, and you’ll receive a “unique constraint violated” error messages. That means you can’t import one application into the workspace of the other, even if you are using a different application ID.
    As far as I can see, the only viable way of doing an application merge is to have two identical workspaces, on two separate APEX instances. The two applications should share the same application ID, although this parameter can be changed in the import file. You should export the page in one application – on the first instance – and import it into the other application – on the second instance.
    You should also make sure that the exported page ID doesn’t exist on the target application, otherwise it will be replaced by the new imported page. Also, if the imported page include references to shared components that are not defined on the second application, it might also pose a problem.
    As I said, this is not trivial. The benefits are mostly depend on the amount and complexity of the pages you want to merge. If they are not many, and simple, you should consider just re-creating them on the target application. If they are very complex, the merge might fail anyway.
    Regards,
    Arie.
    Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.

  • Can I use iCloud to sync two devices with different apples Ids?

    Can I use iCloud to sync two devices with different apple ID's

    What do you mean by "apple ID"?  There's an ID you can use at the iTunes store to buy songs, apps, etc.  there's an ID you can use for your iCloud account - the two can be different or the same. So which service are you referring to when you talk about an apple ID?

  • HT204053 I have two iphones with different numbers that I use my apple ID for purchases, etc.  How do I get my second iphone setup on icloud?  I would like to use the features of icloud for both of my iphones.  Thank you

    I have two iphones with different phone numbers that I use.  I have one of them set up on icloud now, but do not know how to set up my second device on icloud.  Both of my iphones use my same Apple ID for purchases, etc.  Is there a simple way to add a device to my icloud account?  Thank you in advance for any help someone may be able to give me.

    To move one of the phones to a different iCloud account (if that's what you want to do), go to Settings>iCloud and turn all synced data to Off.  When prompted, choose to keep the data on your iPhone.  After everything is off, scroll to the bottom and tap Delete Account.  This will delete the account from the phone but not from iCloud so the other phone will not be effected.  Then set up a new iCloud account with a different Apple ID and turn iCloud syncing in Settings>iCloud back to On.  When prompted, choose Merge.  This will upload the data to the new iCloud account.
    You will then have to go to icloud.com and sign into each iCloud account separately and delete any unwanted data that you don't want on the phone syncing with each account.

Maybe you are looking for