COMPARE DATES IN A CLAUSE 'WHERE'

CREATE TABLE POS.PRODUCTS
PRODUCT_ID NUMBER(9,0),
PRODUCT_NAME VARCHAR2(50),
PRODUCTO_DATE DATE
PRIMARY KEY ( PRODUCTO_ID )
ENABLE NOVALIDATE
I HAVE THIS TABLE, IN WHICH I HAVE A CALL FIELD +(PRODUCT_DATE)+
HERE I AM TRYING TO MAKE A +(SELECT)+, WHERE I WANT TO FILTER A RANGE OF DATES FOR THE FIELD +(CAMPO PRODUCT_DATE)+
I DO IT FOR YOU AS FOLLOWS:
WHERE PRODUCT_DATE> = '28 / 06/2010 'AND PRODUCT_DATE <= '28 / 11/2010'
AND HE TRIED TO FUNCTION TO_DTAE, TO_CHAR
WHAT YOU HAVE RECORDS IN THE TABLE ARE IN THE FIELD PRODUCT_DATE: *28/06/2010, 28/11/2010*
BETWEEN USE IS NOT THE WAY TO BE INSERTING THE REGISTRATION IN THE FIELD OR THE FORMAT, AND HOPE SOMEONE LIKE SEPA CORRECT COMPARISON BETWEEN DATES OF FORM
THANKS FOR YOUR TIME, GREETING

try dis,
where to_date(product_date,'dd-mon-yy')>=to_date('28/06/2010','dd/mm/yy') and to_date(product_date,'dd-mon-yy')<=to_date('28/11/2010','dd/mm/yy');
or
where to_date(product_date,'dd-mon-yy') between to_date('28/06/2010','dd/mm/yy') and to_date('28/11/2010','dd/mm/yy');Regards,
Santosh.Minupurey

Similar Messages

  • Edit the clause where in a datablock

    i want to edit the clause where in a datablock in forms 10g
    je veux que to_date(champdb,'dd/mm/yyyy') = :champforms
    je fais
    set_block_property('plombage',DEFAULT_WHERE ,'to_date(dateplomb,'dd/mm/yyyy')= decode(:dateplombage,null,DATEPLOMB,'||:dateplombage||')');

    Ok, but if you want to compare the data without time-part, don't use to_char, user TRUNC(DATEPLOMB), and instead of your code
    to_date(to_char(sysdate,'dd/mm/yy hh24:mi'),'dd/mm/yy hh24:mi')its simpler to use
    trunc(sysdate, 'MI')

  • Comparing data b/w biw and oltp

    hi
    Could some one can halp me how to compare data between biw and oltp system.which has been extracted.
    Thank for your precious time spent to help me in learning.
    Thanks,
    Jagadeesh

    Jagadish,
    It is not always all extracted data are coming from one standard table and comparison is easy. most of the time from multiple tables. There are couple of things you can do.
    1. If you know any R3 functionals you can inquire about reports available that produce the same kind of column groupings.
    2. If no one exists or do not get much help from them, and if you have SQ01 access in R3 you can create a query to bring the same columns fromcorresponding tables (This is a harder because you need access and need to findout from where data is coming from though info is available in help.sap.com).
    3. more practical would be select a small subset of data, with right filters in your selection columns of the info package and extract data, at the same time use the same selection in RSA3 (R3 side) to extract data and compare. This should tell you whether what you have in R3 is matching with the extracted data.
    4. After your transformations you can compare the same with your info provider (cube or ODS) contents as well.
    hope this helps,
    Award points if useful.
    Alex (Arthur Samson)

  • Procedure Confirmed with Comparing Dates

    Trying to compare two dates, and there's so many ways I'm
    just getting a bit
    confused.
    I have a date stored in my database in a timestamp field with
    this format:
    2006-03-05 19:13:05
    I have a term defined in months (in the database) of how long
    the account is
    valid:
    term: 12
    I can now almost get the expired date, with this code, where
    $vDate is the
    untouched date from my database, and $term is the term in
    months.
    $blog2 = date("M jS Y",strtotime($vDate,'+'.$term.'
    Month'));
    But it only increments the months, not the years.
    Now, here's my problem:
    I can create an array with expired and current dates, but
    then I have to
    construct a moderately complex if/elseif statement to check
    year, then
    month, then day.
    Is there a better way? IE, can anybody think of a method in
    which I can
    compare the dates more efficiently? I'm going in circles.
    Everytime I
    think I've almost got it, I lose something.
    Any suggestions?
    TIA,
    Jon

    David, thank you for replying.
    I was just looking at doing it with SQL, but here is my
    question/problem:
    I am doing this for a client database of hosting customers -
    a one-stop list
    so we can see who's due. I'm worried about having two sql
    queries per
    customer. Currently it wouldn't be a big deal, but hopefully
    in the future
    it would be.
    Can you confirm this would be an issue? If it is an issue,
    can you take a
    peek at my code below? Can you confirm I'm either bass
    ackwards or on the
    right track to do this in PHP? As I stated, if there's an
    easy SQL solution
    that won't cause extra load on the server, cool.
    I'm doing it as such now (my previous method was not
    working):
    $dates1 = create_Dates($renewDate);
    //Create_dates function listed below
    $status = account_expire($dates1);
    echo $status;
    //account_expire function below:
    //Create Dates function:
    function create_Dates($date){
    $date = strtotime($date);
    $dates['eM'] = date("m",$date);
    $dates['eD'] = date("j",$date);
    $dates['eY'] = date("Y",$date);
    $dates['cM'] = date("m");
    $dates['cD'] = date("j");
    $dates['cY'] = date("Y");
    return $dates;
    //and this long bore is my if/else to check dates:
    function account_expire($dateAray){
    //exploding an array would be best
    $eM = $dates['eM'];
    $eD = $dates['eD'];
    $eY = $dates['eY'];
    $cM = $dates['cM'];
    $cD = $dates['cD'];
    $cY = $dates['cY'];
    //this is where we begin calculating
    if($eY > $cY){ //07 > 06
    $status = 'Paid';
    return $status;
    elseif($eY < $cY){
    $status = 'EXPIRED';
    return $status;
    elseif($eY == $cY){
    if($eM > $cM){
    $status = 'Paid';
    return $status;
    elseif($eM < $cM){
    $status = 'EXPIRED';
    return $status;
    elseif($eM == $cM){
    if($eD > $cD){
    $status = 'EXPIRED';
    return $status;
    elseif($eD <= $cD){
    $status = 'Paid';
    return $status;
    >
    > Use the MySQL DATE_ADD() function:
    >
    >
    http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html
    >
    > SELECT registered, DATE_ADD(registered, INTERVAL 12
    MONTH) AS expiry
    > FROM myTable
    >
    > If your expiry dates are always 12 months ahead, that
    can be hard coded
    > into your SQL. If the terms are variable, do a SELECT
    query first to get
    > the term, then do a second query using the first result.

  • Compare data from a table

    Hello, I am trying to compare data from one and the same table. In short I have:
         NAME     DTM     CHARGE
         Atanas     8/18/2012 9:33:23 AM     100
    Atanas     8/18/2012 9:33:23 AM     101
         Niki     8/18/2012 9:33:43 AM     200
         Niki     8/17/2012 9:34:10 AM     100
    Niki     8/18/2012 9:33:43 AM     201
         Niki     8/17/2012 9:34:10 AM     101
         Atanas     8/17/2012 9:34:29 AM      50
    Atanas     8/17/2012 9:34:29 AM      51
         Joro     8/18/2012 12:10:12 PM 400
         Joro     8/17/2012 12:10:21 PM 300
    Joro     8/18/2012 12:10:12 PM 401
         Joro     8/17/2012 12:10:21 PM 301
    And I want to sum CHARGE for each DTM for each NAME and present the difference in an additional column, the output should be like that:
    NAME     DTM     CHARGE DTM CHARGE DIFFERENCE
         Atanas     8/17/2012 9:33:23 AM     101 8/18/2012 9:33:23 AM 201 - 100
    Niki     8/17/2012 9:33:23 AM     201 8/18/2012 9:33:23 AM 401 - 200
    Joro     8/17/2012 9:33:23 AM     601 8/18/2012 9:33:23 AM 801 200
    the DTM will be always /sysdate - 2/ and /sysdate - 1/,
    Thanks in advance!

    It is not clear what you are trying to do, but it looks like:
    with sample_table as (
                          select 'Atanas' name,to_date('8/18/2012 9:33:23 AM','mm/dd/yyyy hh:mi:ss am') dtm,100 charge from dual union all
                          select 'Atanas',to_date('8/18/2012 9:33:23 AM','mm/dd/yyyy hh:mi:ss am'),101 from dual union all
                          select 'Niki',to_date('8/18/2012 9:33:43 AM','mm/dd/yyyy hh:mi:ss am'),200 from dual union all
                          select 'Niki',to_date('8/17/2012 9:34:10 AM','mm/dd/yyyy hh:mi:ss am'),100 from dual union all
                          select 'Niki',to_date('8/18/2012 9:33:43 AM','mm/dd/yyyy hh:mi:ss am'),201 from dual union all
                          select 'Niki',to_date('8/17/2012 9:34:10 AM','mm/dd/yyyy hh:mi:ss am'),101 from dual union all
                          select 'Atanas',to_date('8/17/2012 9:34:29 AM','mm/dd/yyyy hh:mi:ss am'),50 from dual union all
                          select 'Atanas',to_date('8/17/2012 9:34:29 AM','mm/dd/yyyy hh:mi:ss am'),51 from dual union all
                          select 'Joro',to_date('8/18/2012 12:10:12 PM','mm/dd/yyyy hh:mi:ss am'),400 from dual union all
                          select 'Joro',to_date('8/17/2012 12:10:21 PM','mm/dd/yyyy hh:mi:ss am'),300 from dual union all
                          select 'Joro',to_date('8/18/2012 12:10:12 PM','mm/dd/yyyy hh:mi:ss am'),401 from dual union all
                          select 'Joro',to_date('8/17/2012 12:10:21 PM','mm/dd/yyyy hh:mi:ss am'),301 from dual
    select  nvl(s1.name,s2.name) name,
            s1.dtm,
            s1.charge,
            s2.dtm,
            s2.charge,
            s2.charge - s1.charge diff
      from      (
                 select  name,
                         dtm,
                         sum(charge) charge
                   from  sample_table
                   where dtm >= trunc(sysdate) - 1
                     and dtm <  trunc(sysdate)
                   group by name,
                            dtm
                ) s1
            full join
                 select  name,
                         dtm,
                         sum(charge) charge
                   from  sample_table
                   where dtm >= trunc(sysdate)
                     and dtm <  trunc(sysdate) + 1
                   group by name,
                            dtm
                ) s2
              on s1.name = s2.name
    NAME   DTM           CHARGE DTM           CHARGE       DIFF
    Atanas 17-AUG-12        101 18-AUG-12        201        100
    Niki   17-AUG-12        201 18-AUG-12        401        200
    Joro   17-AUG-12        601 18-AUG-12        801        200
    SQL> SY.

  • How to compare date and time together

    Hi,
    How to compare Date and Time together?
    For example in a database table there are two fields rundate and runtime.  I want to compare these two with perticular date and time in the program.  Like, I want to pull all the records where the records's date and time are less than a perticular date and time in the program.
    Hope the question is clear...
    Thanks.
    Kavita

    Hi Kavita
    There is no as such Date and Time Comparision FM in Standard SAP  But You can define your own like this
    <b>FUNCTION ZAV4_COMPAREDATETIME.
    ""Lokale Schnittstelle:
    *"  IMPORTING
    *"     REFERENCE(DATE1) TYPE  DATS
    *"     REFERENCE(TIME1) TYPE  TIMS
    *"     REFERENCE(DATE2) TYPE  DATS
    *"     REFERENCE(TIME2) TYPE  TIMS
    *"  EXPORTING
    *"     VALUE(TWOISMORETOPICAL) TYPE  C
      twoismoretopical = ''.
      if date2 > date1.
        twoismoretopical = 'X'.
      else.
         if date2 = date1 and time2 > time1.
           twoismoretopical = 'X'.
         endif.
      endif.
    ENDFUNCTION.</b>
    Regards
    Mithlesh

  • Compare date in SQL statement

    yup.. how can i compare date in SQL statement??
    pls give me a completed example.

    I'd think this is a formatting problem. Why not try:
    PreparedStatement ps = myConnection.prepareStatement(
    "SELECT * FROM Receipt WHERE to_date(Date) > ? ");
    ps.setDate(1,TodayDate);
    ResultSet rs = ps.executeQuery();
    HTH,
    Ken

  • How to compare Date/time string

    I read from datalog file including Date/time string ,and want to query the special Date/time string span ,how to compare the data/time string ?

    Hello Joshua,
    To compare date/time you have to extract the different components (day, month, year, hour, minute, second) anyway. Why not "convert to seconds"? I think it's easier to compare one number (where you also can do other math, like calc the difference and so on) than to compare seven (?) parameters with some exceptions... If the dates are read from excel (there was a similar thread some days ago), why not convert to seconds in excel (just a format change)?
    Best regards,
    GerdW
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Compare date with time

    Hi ,
    Oracle 10.2.0.1.0
    I need to compare date field with time stamp as well . I tried doing byt getting time stamp using to_char and on convertion into date by using to_date , I'm loosing time stamp please help

    804282 wrote:
    I need to compare date field with time stamp as well Compare how exactly?
    If you for example want to see if the date and timestamp are "equal", you can use the following approach - where in this specific approach it is deemed that if the difference between the timestamp and date is less than 1 sec, the two values are equal. E.g.
    SQL>
    SQL> create table test_tab(
      2          d       date,
      3          t       timestamp
      4  );
    Table created.
    SQL>
    SQL> insert into test_tab values( sysdate, systimestamp );
    1 row created.
    SQL> --// is the date and timestamp within 1 sec of one another?
    SQL> select * from test_tab where t-d <  to_dsinterval('0 0:0:1.00');
    D                   T
    2011/07/12 07:25:06 12/JUL/11 07:25:06.744832
    SQL> --// the reverse test
    SQL> select * from test_tab where t-d >=  to_dsinterval('0 0:0:1.00');
    no rows selected
    SQL>

  • Question - Comparing data from 2 databases

    I'm new to Oracle - I'm trying to compare data from 2 separate databases.
    I'm trying to get data from both databases based on a common TRACKING_NUMBER. The issue is that in one database there are additional 0s in front of the Tracking_Number.
    So I'm trying to find out what I can put in my query to remove those zero's in front of the tracking number. I have the query below - it's very long.
    SELECT DISTINCT cm.TRACKING_NUMBER_TYPE AS HType,
    TRUNC(cm.CREATED_DATE) as CodeMoveDate,
    SUBSTR(cm.CODE_MOVE_DESC, 1, 50) AS Description,
    cm.TRACKING_NUMBER AS TrackingNumber,
    rq.Plant_Name as Location,
    jr_eur.Assignee as Tracker,
    TRUNC(MAX(jr_spec.Journal_Date)) as Date_Spec,
    TRUNC(MAX(jr_app.Journal_Date)) as Date_Approved,
    TRUNC(MAX(jr_ut.Journal_Date)) as Date_Unit,
    TRUNC(MAX(jr_qa.Journal_Date)) as Date_Assurance,
    TRUNC(MAX(jr_eur.Journal_Date)) as Date_Enduser,
    TRUNC(MAX(jr_gv.Journal_Date)) as Date_Gatekeeper,
    TRUNC(MAX(jr_prod.Journal_Date)) as Date_Move,
    TRUNC(MAX(jr_eun.Journal_Date)) as Date_Notification,
    TRUNC(MAX(jr_pver.Journal_Date)) as Date_Production,
    TRUNC(MAX(jr_udoc.Journal_Date)) as Date_Documentation
    FROM PROJMAN.PM_CODE_MOVES_V cm,
    PROJMAN.PM_Requests_V rq,
    PROJMAN.PM_Journals_V jr_spec,
    PROJMAN.PM_Journals_V jr_app,
    PROJMAN.PM_Journals_V jr_ut,
    PROJMAN.PM_Journals_V jr_qa,
    PROJMAN.PM_Journals_V jr_eur,
    PROJMAN.PM_Journals_V jr_gv,
    PROJMAN.PM_Journals_V jr_prod,
    PROJMAN.PM_Journals_V jr_eun,
    PROJMAN.PM_Journals_V jr_pver,
    PROJMAN.PM_Journals_V jr_udoc
    WHERE cm.TRACKING_NUMBER = LTRIM(rq.Request_ID(+))
    AND cm.TRACKING_NUMBER = jr_spec.Request_ID(+)
    AND cm.TRACKING_NUMBER = jr_app.Request_ID(+)
    AND cm.TRACKING_NUMBER = jr_ut.Request_ID(+)
    AND cm.TRACKING_NUMBER = jr_qa.Request_ID(+)
    AND cm.TRACKING_NUMBER = jr_eur.Request_ID(+)
    AND cm.TRACKING_NUMBER = jr_gv.Request_ID(+)
    AND cm.TRACKING_NUMBER = jr_prod.Request_ID(+)
    AND cm.TRACKING_NUMBER = jr_eun.Request_ID(+)
    AND cm.TRACKING_NUMBER = jr_pver.Request_ID(+)
    AND cm.TRACKING_NUMBER = jr_udoc.Request_ID(+)
    AND jr_spec.Journal_Status(+) = 'Spec Doc'
    AND jr_app.Journal_Status(+) = 'Approved'
    AND jr_ut.Journal_Status(+) = 'Unit Test'
    AND jr_qa.Journal_Status(+) = 'Quality Assurance'
    AND jr_eur.Journal_Status(+) = 'End User Review'
    AND jr_gv.Journal_Status(+) = 'Gatekeeper Verificat'
    AND jr_prod.Journal_Status(+) = 'Move to Production'
    AND jr_eun.Journal_Status(+) = 'End User Notificatio'
    AND jr_pver.Journal_Status(+) = 'Production Verificat'
    AND jr_udoc.Journal_Status(+) = 'User Documentation'
    AND cm.TRACKING_NUMBER_TYPE = 'H'
    and cm.CREATED_DATE >{d '2006-12-31'}
    GROUP BY
    cm.TRACKING_NUMBER_TYPE,
    TRUNC(cm.CREATED_DATE),
    cm.CODE_MOVE_DESC,
    cm.TRACKING_NUMBER,
    rq.Plant_Name,
    jr_eur.Assignee
    ORDER BY TRUNC(cm.CREATED_DATE)

    I recommend using a product.
    I used to write scripts and procedures, but no more!
    Reason is: you save time. A lot of time. You pay few hunderes $ once for the product.
    If you do it yourself, you waste half-days doing it properly.
    A good tool for database compare is Comparenicus (www.compareniucs.com).
    I'm using it for 6 months now and it saves me a lot of time.

  • Performance question when compare date with date or char with char

    Hello from Germany (Frankfurt) !
    I am working on Oracle 9.2.0.8.0
    and have to solve following problem:
    Comparison of a date and char fields.
    Now two ways to do it.
    Either I compare char with char and convert date to char,
    or I compare date with date and convert char to date.
    Now the performace question. Which operation takes more effort for the database?
    So why not to try and to see the results?
    First create table:
    CREATE TABLE TEST (
    char_date VARCHAR2(8),
    real_date DATE
    NOLOGGING;
    Then insert 1.000.000 rows
    BEGIN
    for x in 1..1000000
    loop
    insert into test (char_date, real_date) VALUES('19990101', TO_DATE('2006.01.01', 'YYYY.MM.DD'));
    end loop;
    COMMIT;
    END;
    Collect statistics
    EXEC dbms_stats.gather_table_stats('TESTER', 'TEST');
    Now run some selects for date to char conversion:
    Elapsed: 00:00:00.00
    SQL> select * from test t where TO_DATE(char_date, 'YYYYMMDD') > real_date;
    no rows selected
    Elapsed: 00:00:03.02
    SQL> select * from test t where TO_DATE(char_date, 'YYYYMMDD') > real_date;
    no rows selected
    And some selects for char to date conversion:
    Elapsed: 00:00:03.02
    SQL> select * from test t where char_date > TO_CHAR(real_date, 'YYYYMMDD');
    no rows selected
    Elapsed: 00:00:02.05
    SQL> select * from test t where char_date > TO_CHAR(real_date, 'YYYYMMDD');
    no rows selected
    Elapsed: 00:00:02.05
    SQL>
    As you see when I compare char with char and convert date to char it seems to be faster (almost 1 second)
    Is the test correct?
    I still not sure, what gets better performance...
    Any idea?
    Thanks!

    Depends on whether you want the right results or not.
    Why don't you run the following two queries and see if the difference in results tells you anything?:
    with t as (select to_date('01/02/2007', 'dd/mm/yyyy') date_col from dual
               union all
               select to_date('02/02/2007', 'dd/mm/yyyy') from dual
               union all
               select to_date('03/02/2007', 'dd/mm/yyyy') from dual
               union all
               select to_date('03/03/2006', 'dd/mm/yyyy') from dual)
    select *
    from   t
    where  date_col < to_date('04/03/2006', 'dd/mm/yyyy');
    with t as (select to_date('01/02/2007', 'dd/mm/yyyy') date_col from dual
               union all
               select to_date('02/02/2007', 'dd/mm/yyyy') from dual
               union all
               select to_date('03/02/2007', 'dd/mm/yyyy') from dual
               union all
               select to_date('03/03/2006', 'dd/mm/yyyy') from dual)
    select *
    from   t
    where  to_char(date_col) < '04/03/2006';

  • Wanna compare data in excel with real time signal

    Hi,
     my application is to check the PCB i/o pins... first i have to corresponding signal to every pin in GOOD PCB board and the output of each pin should saved in excel with the help of write to spreadsheet.. then the database be act as master for other PCB boards..
    If i wanna check the other pcb board means the same corresponding signals should be send to the each pin of the PCB board.. the Output received from the board should check with the data already saved in the database if it is match's means Status LED should Glow otherwise its not to glow...
    pls help me to finish this application.. i have attach model vi with post and excel too....
    Regards,
    N. Srinivasan
    Solved!
    Go to Solution.
    Attachments:
    PCB_COMPARING.vi ‏184 KB
    DATABASE.xls ‏2 KB

    The "method" you have in your last post doesn't come anywhere near to what you say you want to do.
    It creates a simulated sinewave and writes it to a text file.  Waits 1/10th of a second, reads it back from that text file, does a lot of manipulation to that data to convert it to a dynamic waveform type.  Then compares it to another simulated sinewave to say if they are equal or not.
    "My doubt is if all the received signal are saved in the excel sheet first..".  I don't know why you would doubt that this would happen.  If you receive a signal and write it to the text file, then why don't you believe it would be written to a text file?  By the way, the Read from Spreadsheet File and Write to Spreadsheet File functions have nothing to do with Excel.  They read or write data to a text file that happens to be formatted in a way (delimiters between data in a row, end of line characters between rows) that is a text file version of a spreadsheet.  Excel has the ability to import from or export to a text file, but that file is NOT an Excel file.
    You have major portions of your code missing and questions to be answered.
    Where are you actually outputing a signal to the printed circuit board?
    Where are you actually receiving a signal from the printed circuit board?
    Are you receiving one signal or 40 signals?
    What type of DAQ board are you using to do this?
    Okay, let's say once you have the first portion of your code set up to do that, you can write the data to a text file.
    Now in another part of your code, you basically repeat the procedure but instead of writing to a text file, you read the data from your "good board" text file and compare the two.
    How do you compare the signals and determine whether the newly read signal is good or bad?  Right now, you are doing a comparison for equality.  Do you think the "good" signal and the newly test signal will ever be equal?  Even if you just repeat the test on the good board, do you think those signals will be equal?  NO.  It is impossible for the signals to ever be equal, even the slightest variation in the signal is going to make them unequal.  You are never going to measure identical real world signals identically.  You need to come up with some comparison algorithm with criteria that determines whether another good signal actually matches your saved good signal, and a bad signal does not match the good signal taking into account the variations you inevitably get when measuring real world signals.
    Those are big questions you need to answer.  Assuming you work all that out, on paper in a design specification document, only then can you start worrying about the LabVIEW program and its architecture.  Ultimately, a state machine architecture will be your likely choice as you have multiple states to work with.  Initialize, test board, save data to file, read data from file, compare data, possibly more states such as wait, close program, multiple states within the test board process as it is probably a multiple step process.

  • Compare data between two tables all coullms

    Hi All,
    I have a task to compare data for the dev and prod data for the same table ,can some one please help me with the script for this ...
    Thanks in Advance..

     SELECT Foo.*, Bar.*
       FROM Foo
            FULL OUTER JOIN
            Bar
            ON Foo.c1 = Bar.c1
               AND Foo.c2 = Bar.c2
               AND Foo.cn = Bar.cn
     WHERE Foo.key IS NULL 
        OR Bar.key IS NULL; 
    Best Regards,Uri Dimant SQL Server MVP,http://sqlblog.com/blogs/uri_dimant/
    Blog : MS SQL Development and Optimization
    Blog : Large
    scale of database and cleansing

  • Comparing data in the database with the input text

    hi there i have problem with the comparing data in the database with the input text. here is the piece of code of mine:
    //declaration
    datasourcedb.connect();
    String stcode = req.getParameter("txtCode");
    ResultSet rs = null;
    String action = req.getParameter("action");
    ResultSet portquery = null;
    if (action.equals("SELL"))
    -->portquery = datasourcedb.query("SELECT stockcode FROM portfolio where stockcode =\'"+ stcode + "\'");
    -->portquery.next();
    -->if((portquery.wasNull()) == true)
    disp = req.getRequestDispatcher("error.jsp"); }
    else */
    Status = "Sell";
    datasourcedb.close();
    with the code that i marked with --> it doesnt work since i have to compare the input text stcode with stockcode in the db. could anyone tell me how to compare it?
    regards
    virginia

    i have try to change into this code:
    if (action.equals("SELL"))
    portquery = datasourcedb.query("SELECT distinct stockcode FROM portfolio where stockcode =\'"+ stcode + "\' + and userName = \'"+ user + "\'");
    if(portquery.next()) {
    Status = "Sell";}
    else {               
    disp = req.getRequestDispatcher("error.jsp");
    but so far the coding doesnt give any result.... could anyone help me? since the coding does not reach status n the disp

  • Compare data between two tables of same schema

    Folks,
    I have one very intresting query which i would like to share with you all and looking forward for the solution asap.
    Scenario
    I have two table say TableA and TableB, both having same structre say as below
    TableA
    Col1 Var(10)
    Col2  INT
    TableB
    Col1 Var(10)
    Col2  INT
    I want to compare data between these two tables and store compared data into third table, let me expalin the whole scenario.
    TableA
    ColA          ColB
    INDIA          1
    PAKistan      2
    TableB
    ColA          ColB
    INDIA          1
    PAK             3
    I want result like
    Difference
    ColA          ColB
    True            0
    False           -1
    I want to store this difference in thrid table.
    i.e. when comparing text, i need TRUE when compare 100% else False, Caption is not considered.
         When comparing numeric value, simple sub is requried , TableA-TableB
    Note - I dont want to use any external tool to compare the table data, i required sql query to do the same.
    Thanks
    Amit Srivastava
    Amit
    Please mark as answer if helpful
    http://fascinatingsql.wordpress.com/

    Whereas the abbreviation of countries that exist in Table2 table are the first three letters of the name of the country*, here's a suggestion:
    -- code #1 v2
    INSERT into [Difference] (Col1, Col2, ACol1, BCol1)
    SELECT case when A.Col1 = B.Col1 then 'true' else 'false' end,
    (IsNull(A.Col2, 0) - IsNull(B.Col2, 0)), A.Col1, B.Col1
    from TableA as A full outer join
    TableB as B on (A.Col1 = B.Col1
    or Left(A.Col1, 3) = B.Col1);
    Is the COLLATE database case insensitive? If not, the code #1 above will have to be modified, using the upper () function or using COLLATE case insensitive in A.Col1 and B.Col1 columns.
    But if the abbreviation of the country follow the
    ISO 3166-1 alpha-3 standard, will require a fourth table containing the symbol and name of countries.
    -- code #2 v2
    ;with
    TableB_2 as (
    SELECT case when Len(Col1) = 3
    then (SELECT Country_name from [ISO 3166-1 a3] where Cod = Col1)
    else Col1 end as Col1, Col2
    from TableB
    INSERT into [Difference] (Col1, Col2, ACol1, BCol1)
    SELECT case when A.Col1 = B.Col1 then 'true' else 'false' end,
    (IsNull(A.Col2, 0) - IsNull(B.Col2, 0)), A.Col1, B.Col1
    from TableA as A full outer join
    TableB_2 as B on A.Col1 = B.Col1;
    Structure and data to test:
    use tempdb;
    CREATE TABLE TableA (Col1 varchar(10), Col2 int);
    CREATE TABLE TableB (Col1 varchar(10), Col2 int);
    CREATE TABLE [Difference] (Col1 varchar(10), Col2 int, ACol1 varchar(10), BCol1 varchar(10));
    INSERT into TableA values ('INDIA', 1), ('PAKistan', 2), ('China', 12);
    INSERT into TableB values ('INDIA', 1), ('PAK', 3), ('Bhutan', 3);
    go
    CREATE TABLE [ISO 3166-1 a3] (Cod char(3) primary key, [Country_name] varchar(30));
    INSERT into [ISO 3166-1 a3] values
    ('IND', 'India'), ('PAK', 'Pakistan'), ('CHN', 'China'), ('BGD', 'Bangladesh'),
    ('BTN', 'Bhutan'), ('MMR', 'Myanmar'), ('NPL', 'Nepal');
    go
    (*) If the short form of the country name using the first three letters of the country name,
    false positives can occur. For example,
    Mali and Malta or
    Angola and Anguilla.
    José Diz     Belo Horizonte, MG - Brasil

Maybe you are looking for