How to write a sql query to retrieve data entered in the past 2 weeks

Hi,
I have file names and last accessed date(java.sql.Date format) stored in my database table, I would like to know how I can write a query to get the name of files accessed in the past 2 weeks,I use open sql server at the back end.
Thanks in advance.

This has essentially nothing to do with JDBC. JDBC is just an API to execute the SQL language using Java and thus interact with the databases.
Your problem is related to the SQL language, you don't know how to write the SQL language. I suggest you to go through a SQL tutorial (there is one at w3schools.com) and to read the SQL documentation which come along with the database in question. A decent database manfacturer has a website and probably also a discussion forum / mailinglist as well.
I'll give you a hint: you can just use equality operators in SQL like everywhere. For example: "WHERE date < somedate".

Similar Messages

  • How to write a SQL query in SAP B1 2007 B with input parameters?

    How to write a SQL query in SAP B1 2007 B with input parameters, on execution of which will ask for some input value from the user and the values will be selected from a list such as item list?

    The syntax like
    SELECT * FROM OITM T0 WHERE T0.ItemCode = '[%0\]'
    Thanks,
    Gordon

  • How to run recordset SQL query in FORM DATA event

    How can I run recordset SQL query in FORM DATA event upon clicking on Add button in the document?

    Hi Slamet,
    When you receive a form data event you have a class containing inside it a ObjectKeys xml info regarding the object added/modified,...
    With the objects keys you can then use the DI API method called GetByKeys to obtain the DI Object.
    There is some information about it in the SDK Help file, mainly in the "FormDataEvent" class definition:
    <i>The event provides the unique ID (BusinessObjectInfo.ObjectKey) of the modified business object. You can use the value of this property as an input parameter in the DI API DataBrowser.GetByKeys method to get a DI object.</i>
    Pay attention you don't have this information in the Before=True event of the Add as it is not yet in the database.
    Hope it helps
    Trinidad.

  • How to write this sql query in php code ?

    for example:
    insert into temp
    select *
    from testtable;
    after this, i will query data from sql below:
    select *
    from temp;
    how to write this php code ?
    who can help me ?
    thanks!

    Have a look at the manual to find out how to issue queries.
    http://us3.php.net/oci8

  • How to write this SQL query

    We have a table, the structure as below: (I put a blank row in the middle to make it clear)
    Product_ID     Retailer     Retail_Price
    1001          A          1.2
    1001          B          1.5
    1001          C          1.4
    1002          B          2.0
    1002          C          2.1
    1002          E          1.8
    1002          F          2.0
    1003          A          1.7
    1003          C          1.5
    Basically we use the table to compare the retail price for different retailers in terms of different products. My customer asked me to give a report based on above table but only shows the retail prices which contain retailer A.
    For example, on above table I need to give a report like below:
    Product_ID     Retailer     Retail_Price
    1001          A          1.2
    1001          B          1.5
    1001          C          1.4
    1003          A          1.7
    1003          C          1.5
    Can anybody give some ideas on how I should write a SQL to achieve this.
    Many thanks!

    SQL> create table product(
    2 Product_ID varchar2(10),
    3 Retailer varchar2(10),
    4 Retail_Price number(7,2)
    5 )
    6 /
    Table created.
    SQL> insert into product values('1001','A',1.2)
    2 /
    1 row created.
    SQL> insert into product values('1001','B',1.5)
    2 /
    1 row created.
    SQL> insert into product values('1001','C',1.4)
    2 /
    1 row created.
    SQL> insert into product values('1002','B',2.0)
    2 /
    1 row created.
    SQL> insert into product values('1002','C',2.1)
    2 /
    1 row created.
    SQL> insert into product values('1002','E',1.8)
    2 /
    1 row created.
    SQL> insert into product values('1002','F',2.0)
    2 /
    1 row created.
    SQL> insert into product values('1003','A',1.7)
    2 /
    1 row created.
    SQL> insert into product values('1003','C',1.5)
    2 /
    1 row created.
    SQL> select * from product
    2 /
    PRODUCT_ID RETAILER RETAIL_PRICE
    1001 A 1.2
    1001 B 1.5
    1001 C 1.4
    1002 B 2
    1002 C 2.1
    1002 E 1.8
    1002 F 2
    1003 A 1.7
    1003 C 1.5
    9 rows selected.
    SQL> select * from product where PRODUCT_ID in (
    2 select distinct PRODUCT_ID from product where RETAILER='A')
    3 /
    PRODUCT_ID RETAILER RETAIL_PRICE
    1001 A 1.2
    1001 B 1.5
    1001 C 1.4
    1003 A 1.7
    1003 C 1.5

  • How To Write A Sql Query to Show 0's

    I never can remember this :-/ What do I have to do to get a SQL Query to return 0 if the Count of a condition is 0?  For example lets say Joe, Jay, Jim could log on, but only Joe & Jim logged in Jay would not be returned in the query below.  What
    would I need to set-up so that All 3 users would be returned
    Select logonName, Count(Logon)
    From logonUserInfo
    where logonName is not nullGROUP BY logonName

    Currently there is only 1 table involved.  I would need a separate table?  What would this table need to hold?
    You wouldn't need a separate table unless and until you want to store who logged in at what time and so on... then your table structures looks like below..
    CREATE TABLE loginnames
    loginid INT
    name VARCHAR(30),
    GO
    CREATE TABLE loginTimes
    loginid INT,
    logintime DATETIME
    GO
    So, now you can do a left join on both tables on a certain date directly and find out who actually logined and who didn't with a count 0 for the one's who didn't login... and that will abide the principles of normalization as well...
    If you don't want to use an another table, you would have to duplicate the loginnames everytime that user logins and also you don't have a track on what date the login happened.. So you will be considering from day 1 to Till date...
    Please mark as answer, if this has helped you solve the issue.
    Good Luck :) .. visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.

  • How to write a SQL Query without using group by clause

    Hi,
    Can anyone help me to find out if there is a approach to build a SQL Query without using group by clause.
    Please site an example if is it so,
    Regards

    I hope this example could illuminate danepc on is problem.
    CREATE or replace TYPE MY_ARRAY AS TABLE OF INTEGER
    CREATE OR REPLACE FUNCTION GET_ARR return my_array
    as
         arr my_array;
    begin
         arr := my_array();
         for i in 1..10 loop
              arr.extend;
              arr(i) := i mod 7;
         end loop;
         return arr;
    end;
    select column_value
    from table(get_arr)
    order by column_value;
    select column_value,count(*) occurences
    from table(get_arr)
    group by column_value
    order by column_value;And the output should be something like this:
    SQL> CREATE or replace TYPE MY_ARRAY AS TABLE OF INTEGER
      2  /
    Tipo creato.
    SQL>
    SQL> CREATE OR REPLACE FUNCTION GET_ARR return my_array
      2  as
      3   arr my_array;
      4  begin
      5   arr := my_array();
      6   for i in 1..10 loop
      7    arr.extend;
      8    arr(i) := i mod 7;
      9   end loop;
    10   return arr;
    11  end;
    12  /
    Funzione creata.
    SQL>
    SQL>
    SQL> select column_value
      2  from table(get_arr)
      3  order by column_value;
    COLUMN_VALUE
               0
               1
               1
               2
               2
               3
               3
               4
               5
               6
    Selezionate 10 righe.
    SQL>
    SQL> select column_value,count(*) occurences
      2  from table(get_arr)
      3  group by column_value
      4  order by column_value;
    COLUMN_VALUE OCCURENCES
               0          1
               1          2
               2          2
               3          2
               4          1
               5          1
               6          1
    Selezionate 7 righe.
    SQL> Bye Alessandro

  • Need efficient SQL query to retrieve data for MLM website

    Table cd_members
    MemberID LeftID RightID
    1 2 3
    2 4 5
    3 6 7
    4 8 -
    5 - -
    6 - -
    7 - -
    8 9 10
    9 - -
    10 - -
    i want to execute a query to retrieve downline of a member say MemberID 2
    o/p should be Records with MemberID 4,5,8,9,10
    i am using this query but don't know how to start from MembeID=2
    select a.memberid, a.tradingid, a.refid, a.parentid, a.node, a.leftid, a.rightid, b.memberid from cd_members a, cd_members b
    where (a.leftid=b.memberid or a.rightid=b.memberid)

    Again, assuming that the number of levels is known, you can just do N self joins (note that I intentionally go one level further than necessary in this case
    SQL> ed
    Wrote file afiedt.buf
      1  with t
      2    as
      3   (
      4      select 1 person, 2 left, 3 right from dual union all
      5      select 2, 4, 5 from dual union all
      6      select 3, 6, 7 from dual union all
      7      select 4, 8, null from dual union all
      8      select 5, null, null from dual union all
      9      select 6, null, null from dual union all
    10      select 7, null, null from dual union all
    11      select 8, 9, 10 from dual union all
    12      select 9, null, null from dual union all
    13      select 10, null, null from dual
    14   )
    15   select t1.left, t1.right, t2.left, t2.right, t3.left, t3.right, t4.left, t
    4.right
    16     from t t1,
    17          t t2,
    18          t t3,
    19          t t4
    20    where t1.person = 2
    21      and t1.left = t2.person(+)
    22      and t2.left = t3.person(+)
    23*     and t3.left = t4.person(+)
    SQL> /
          LEFT      RIGHT       LEFT      RIGHT       LEFT      RIGHT       LEFT
         RIGHT
             4          5          8                     9         10Justin

  • How to write a  SQL based on a  view can get the best performance ?

    Hi ,
        I am thinking about performance of  sql based on VIEW .<b>For the best performance ,How to do when I create  and use a view ?</b>  for example , Should i use key in my where clause as select data from table?  (of cause ,this key refers to the key of table which structure the view. ) , <b>Could you give me any advice on creating and using view in term of performance</b> ?

    Hi Guixin Chen,
    Performance depends on various factors. The major key factors are:
    1.  Result Set should be Small
    2.  Amount of Data Transferred should be minimum.
    3.  Number of Data Transfers should be minimum.
    4.  Search Overhead should be minimum.
    5.  Database Load should be minimum.
    For more details, check the following docs.
    <b>Performance Notes</b>
    http://help.sap.com/saphelp_nw04s/helpdata/en/fc/eb3b7e358411d1829f0000e829fbfe/frameset.htm
    http://help.sap.com/saphelp_nw04s/helpdata/en/5b/320c40ac368f5ce10000000a155106/frameset.htm
    You can also check Performance by,
    1.  Transaction code ST05
    2.   From ABAP Workbench using the menu path Test Performance Trace.
    Dont forget to reward pts, if it helps ;>)
    Regards,
    Rakesh.

  • Why does Oracle SQL query returning a date field without the time component

    Hi,
    I'm a novice SQL user & hv just installed Oracle SQL developer (Version 3.0.04, Build MAIN-04.34).
    I made the same SQL query using "Oracle SQL developer" & "TOAD for Oracle 9.0.1" but I got 2 different format on the same date field:
    On TOAD, I get the date field extracted as *04/26/2011 23:12:58*
    On Oracle, I get the date field extracted as *26/APR/11*
    Why is the Oracle result in a different format & missing the time component?
    Is there any option/preference that I need to set in Oracle SQL developer to get the full date/time format displayed?
    I've tried to set my the date format to DD/MON/RR HH12:MI:SSXFF AM under the preference -> database NLS but I still get the same format!
    Plse help!

    hokim wrote:
    Hi,
    I'm a novice SQL user & hv just installed Oracle SQL developer (Version 3.0.04, Build MAIN-04.34).
    I made the same SQL query using "Oracle SQL developer" & "TOAD for Oracle 9.0.1" but I got 2 different format on the same date field:
    On TOAD, I get the date field extracted as *04/26/2011 23:12:58*
    On Oracle, I get the date field extracted as *26/APR/11*
    Why is the Oracle result in a different format & missing the time component?
    Is there any option/preference that I need to set in Oracle SQL developer to get the full date/time format displayed?
    I've tried to set my the date format to DD/MON/RR HH12:MI:SSXFF AM under the preference -> database NLS but I still get the same format!
    Plse help!http://edstevensdba.wordpress.com/category/nls_date_format/

  • Query on retrieving data back to the program from ALV List

    Hi Group,
    I have a requirement to send the details of the selected data as an ALV list to the user.
    Then, the user selects either 1 or 2 or all or none back to the program from the ALV.
    Thing is that,
    1) when the user selects ( Icon ) to choose all the fields, they were not getting checked and in turn, I was not been able to read the records as checked in the program ( this is for All selection records ).
    2) And also, I am not able to get the records checked ( incase of the user selects all fields ).
    In short, I should be able to read the records which were checked and process only that records.
    please let me know if you have any queries on the same.
    Thank you very much in advance for the help.
    Regards,
    Vishnu.

    hi,
    try like this
    TABLES:     ekko.
    TYPE-POOLS: slis.                           
    TYPES: BEGIN OF t_ekko,
      sel,                         "stores which row user has selected
      ebeln TYPE ekpo-ebeln,
      ebelp TYPE ekpo-ebelp,
      statu TYPE ekpo-statu,
      aedat TYPE ekpo-aedat,
      matnr TYPE ekpo-matnr,
      menge TYPE ekpo-menge,
      meins TYPE ekpo-meins,
      netpr TYPE ekpo-netpr,
      peinh TYPE ekpo-peinh,
    END OF t_ekko.
    DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
          wa_ekko TYPE t_ekko.
    DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
          fieldcatalog1 TYPE slis_t_fieldcat_alv WITH HEADER LINE,
          gd_tab_group TYPE slis_t_sp_group_alv,
          gd_layout    TYPE slis_layout_alv,
          gd_repid     LIKE sy-repid.
    DATA : BEGIN OF det_tab OCCURS 0,
            ebeln LIKE ekpo-ebeln,
           END OF det_tab.
    START-OF-SELECTION.
      PERFORM data_retrieval.
      PERFORM build_fieldcatalog.
      PERFORM build_layout.
      PERFORM display_alv_report.
    *&      Form  BUILD_FIELDCATALOG
          Build Fieldcatalog for ALV Report
    FORM build_fieldcatalog.
      fieldcatalog-fieldname   = 'EBELN'.
      fieldcatalog-seltext_m   = 'Purchase Order'.
      fieldcatalog-outputlen   = 10.
      fieldcatalog-emphasize   = 'X'.
      fieldcatalog-key         = 'X'.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'EBELP'.
      fieldcatalog-seltext_m   = 'PO Item'.
    fieldcatalog-col_pos     = 1.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'STATU'.
      fieldcatalog-seltext_m   = 'Status'.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'AEDAT'.
      fieldcatalog-seltext_m   = 'Item change date'.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'MATNR'.
      fieldcatalog-seltext_m   = 'Material Number'.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'MENGE'.
      fieldcatalog-seltext_m   = 'PO quantity'.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'MEINS'.
      fieldcatalog-seltext_m   = 'Order Unit'.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'NETPR'.
      fieldcatalog-seltext_m   = 'Net Price'.
      fieldcatalog-outputlen   = 15.
      fieldcatalog-do_sum      = 'X'.        "Display column total
      fieldcatalog-datatype     = 'CURR'.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
      fieldcatalog-fieldname   = 'PEINH'.
      fieldcatalog-seltext_m   = 'Price Unit'.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR  fieldcatalog.
    ENDFORM.                    " BUILD_FIELDCATALOG
    *&      Form  BUILD_LAYOUT
          Build layout for ALV grid report
    FORM build_layout.
      gd_layout-box_fieldname     = 'SEL'.
      "set field name to store row selection
      gd_layout-edit              = 'X'. "makes whole ALV table editable
      gd_layout-zebra             = 'X'.
    ENDFORM.                    " BUILD_LAYOUT
    *&      Form  DISPLAY_ALV_REPORT
          Display report using ALV grid
    FORM display_alv_report.
      gd_repid = sy-repid.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program       = gd_repid
          i_callback_user_command  = 'USER_COMMAND'
          i_callback_pf_status_set = 'SET_STAT'
          is_layout                = gd_layout
          it_fieldcat              = fieldcatalog[]
          i_save                   = 'X'
        TABLES
          t_outtab                 = it_ekko
        EXCEPTIONS
          program_error            = 1
          OTHERS                   = 2.
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    " DISPLAY_ALV_REPORT
    *&      Form  DATA_RETRIEVAL
          Retrieve data form EKPO table and populate itab it_ekko
    FORM data_retrieval.
      SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh
       UP TO 10 ROWS
        FROM ekpo
        INTO CORRESPONDING FIELDS OF TABLE it_ekko.
    ENDFORM.                    " DATA_RETRIEVAL
          FORM USER_COMMAND                                          *
          --> R_UCOMM                                                *
          --> RS_SELFIELD                                            *
    FORM user_command USING r_ucomm LIKE sy-ucomm
                      rs_selfield TYPE slis_selfield.
      CASE r_ucomm.
        WHEN '&IC1'.
          IF rs_selfield-fieldname = 'EBELN'.
            READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.
            SET PARAMETER ID 'BES' FIELD wa_ekko-ebeln.
            CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
          ENDIF.
        WHEN 'DET'.  "user presses SAVE
          CLEAR det_tab.
          REFRESH det_tab.
          LOOP AT it_ekko INTO wa_ekko WHERE sel = 'X'.
            MOVE-CORRESPONDING wa_ekko TO det_tab.
            APPEND det_tab.
          ENDLOOP.
          PERFORM build_cat.
          PERFORM dis_data.
      ENDCASE.
    ENDFORM.                    "user_command
    *&      Form  set_stat
          text
         -->RT_EXTAB   text
    FORM set_stat USING rt_extab TYPE slis_t_extab.
      SET PF-STATUS 'ZSTAT' EXCLUDING rt_extab.
    ENDFORM.                    "set_stat
    *&      Form  build_cat
          text
    FORM build_cat.
      CLEAR fieldcatalog1.
      REFRESH fieldcatalog1.
      fieldcatalog1-fieldname = 'EBELN'.
      fieldcatalog1-tabname = 'DET_TAB'.
      fieldcatalog1-seltext_m = 'Order No.'.
      fieldcatalog1-outputlen = 10.
      APPEND fieldcatalog1 TO fieldcatalog1.
      CLEAR fieldcatalog1.
    ENDFORM.                    "build_cat
    *&      Form  dis_data
          text
    FORM dis_data.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program = 'ZTEST_DS'
          it_fieldcat        = fieldcatalog1[]
          i_save             = 'X'
        TABLES
          t_outtab           = det_tab.
    ENDFORM.                    "dis_data
    here i have created one button(DET) in toolbar along with all the buttons of ALV..
    when i click on this i am getting detail list....
    reward if usefull....

  • How to write a sql query to calculate weights using CTE

    Hi guys,
    want some help using a CTE to generate data using recursive SQL - input data in table A to be transformed into table B shown below
    Table A
    Instru_id_index     instru_id_name    instru_id_constit  con_name   weight
            56                       INDEX A                     
    23                  A                 25
            56                       INDEX A                     
    24                 B                  25
            56                       INDEX A                     
    25                  C                 25
            56                       INDEX A                     
    57              
    INDEX  B       25
            57                      
    INDEX B                     31                 
    D                 33
            57                      
    INDEX B                     32                 
    E                  33
            57                      
    INDEX B                     33                 
    F                  33
    (Logic should be recursive in order to be able to handle multi-level, not just level 2.)
    Table B
    Instru_id_index     instru_id_name    instru_id_constit  constit_name   weight
            56                       INDEX A                        
    23                A                   25
            56                       INDEX A                        
    24                B                   25
            56                       INDEX A                        
    25                C                   25
            56                       INDEX A                        
    31                D                   8.3
            56                       INDEX A                        
    32                E                    8.3
            56                       INDEX A                        
    33                F                    8.3
            57                       
    INDEX B                       31                
    D                   33
            57                       
    INDEX B                       32                E                   
    33
            57                       
    INDEX B                       33               
    F                     33
    how can I write a simple CTE construct to  display the data in table B -  How can i calculate the values of weights as 8.3 respectively - calculate these without changing the structure of the tables.
    Can I do this in a CTE

    Full join?
    Anyway, thanks for Rsignh to produces a script with CREATE TABLE and INSERT statements. I've extended the data to one more level of recursion.
    create table weight_tab(
     instrument_id_index int,
     instrument_id_name varchar(10),
     instrument_id_constituent int,
     constituent_name varchar(10),
     [weight] decimal(10,2))
     insert into weight_tab values
     (56,'INDEX A',23,'A',25),(56,'INDEX A', 24,'B',25),
    (56,'INDEX A',25,'C',25),(56,'INDEX A', 57,'INDEX  B',25),
    (57,'INDEX B',31,'D',33), (57,'INDEX B', 32,'INDEX E',33),
    (57,'INDEX B',33,'INDEX C',33),
    (33,'INDEX C',42,'Alfa',60),
    (33,'INDEX C',43,'Beta',40),
    (32,'INDEX C',142,'Gamma',90),
    (32,'INDEX C',143,'Delta',10)
    go
    SELECT * FROM weight_tab
    go
    ; WITH rekurs AS (
        SELECT instrument_id_index, instrument_id_name, instrument_id_constituent,
               cast(weight as float) AS weight, cnt = 1
        FROM   weight_tab a
        WHERE  NOT EXISTS (SELECT *
                           FROM   weight_tab b
                           WHERE  b.instrument_id_constituent = a.instrument_id_index)
        UNION ALL
        SELECT r.instrument_id_index, r.instrument_id_name, w.instrument_id_constituent,
               r.weight * w.weight / 100, r.cnt  + 1
        FROM   rekurs r
        JOIN   weight_tab w ON r.instrument_id_constituent = w.instrument_id_index
        WHERE r.cnt < 4
    SELECT instrument_id_index, instrument_id_name, instrument_id_constituent,
           cast(weight AS decimal(10,2))
    FROM   rekurs
    go
    DROP TABLE weight_tab
    Erland Sommarskog, SQL Server MVP, [email protected]

  • How to write a sql query for this condition?

    i have one table with columns v_sub,v_visit and v_date and the structure is like this
    v_sub v_visit v_date
    1 visit-1 01-mar-09
    1 visit-2 05-mar-09
    1 visit-3 17-mar-09
    2 visit-1 04-feb-09
    2 visit-2 12-mar-09
    2 visit-3 20-mar-09
    i want to write a query which check weather it is in chronological order or not.(for v_sub,v_visit and v_date should be in chronological order as above)
    and i want to check the condition as below:
    v_sub v_visit v_date
    1 visit-1 01-mar-09
    1 visit-2 05-feb-09
    1 visit-3 17-mar-09
    2 visit-1 04-feb-09
    2 visit-2 12-jan-09
    2 visit-3 20-mar-09
    Thanks in advance

    use LAG function to get the previous date
    SQL> -- sample data
    SQL> with t
      2  as
      3  (
      4     select 1 v_sub, 'visit-1' v_visit, to_date('01-mar-09','dd-mon-yy') v_date from dual union all
      5     select 1, 'visit-2', to_date('05-mar-09','dd-mon-yy') from dual union all
      6     select 1, 'visit-3', to_date('17-mar-09','dd-mon-yy') from dual union all
      7     select 2, 'visit-1', to_date('04-feb-09','dd-mon-yy') from dual union all
      8     select 2, 'visit-2', to_date('12-mar-09','dd-mon-yy') from dual union all
      9     select 2, 'visit-3', to_date('20-mar-09','dd-mon-yy') from dual
    10  )
    11  -- end of sample data
    12  select v_sub, v_visit, v_date, lag(v_date) over(partition by v_sub order by v_visit, v_date) v_previous_date
    13    from t
    14  /
         V_SUB V_VISIT V_DATE    V_PREVIOU
             1 visit-1 01-MAR-09
             1 visit-2 05-MAR-09 01-MAR-09
             1 visit-3 17-MAR-09 05-MAR-09
             2 visit-1 04-FEB-09
             2 visit-2 12-MAR-09 04-FEB-09
             2 visit-3 20-MAR-09 12-MAR-09
    6 rows selected.Now you can check if the previous_date is less than v_date

  • How to write a SQL query in Java

    Hi, I'm writing a program that pulls all data from the database with a simple "SELECT * FROM [TABLE NAME]. The problem is that I don't know how to set it up properly. My code will only connect to the database but not execute the query. Please help.
    {code}import java.sql.*;
    import java.util.Properties;
    import java.sql.*;
    public class DatabaseSelect {
    public static void main(String[] args) {
    System.out.println("Connected to the database!");
    Connection conn = null;
    String url = "jdbc:oracle://localhost:1571/";
    String dbName = "jdbc";
    String driver = "com.oracle.jdbc.Driver";
    String userName = "HR";
    String password = "database";
    String query = "SELECT * FROM HR";
    try {
    Class.forName(driver).newInstance();
    conn = DriverManager.getConnection(url+dbName,userName,password);
    System.out.println("Connected to the database");
    } catch (Exception e) {
    e.printStackTrace();
    }{code}

    pbsacct_1 wrote:
    I added it between my System.out statement and the catch exception. This is what I put, but I'm getting the same result. I looks like a lot of errors. The only thing that prints is the "Connected to database".
    Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
    ResultSet.CONCUR_READ_ONLY);
    ResultSet srs = stmt.executeQuery("SELECT * FROM HR");Here is what displays in the console.
    Connected to the database!
    java.lang.ClassNotFoundException: com.oracle.jdbc.Driver
         at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Class.java:164)
         at Discussion10.DatabaseSelect.main(DatabaseSelect.java:26)You are not connecting.
    Because you aren't even loading the driver.
    To be honest if you can't decipher a stack trace with "java.lang.ClassNotFoundException" on your own you are not ready for JDBC anyway.

  • How to write this sql  query to oracle

    Hi sir,
    i am using one query in my sql stored procedure that is:
    select @maxtime=CONVERT(Time,Out_Time+DATEADD(n,60,0)) from shift where Shift_Code = @ShiftCode
    so here i am getting this value 01/01/1900 12:00 AM
    the same i used in oracle my query is :
    to_char(Out_Time,'1900-01-01' + 0/(24*60),'DD/MM/YYYY HH:MI AM')
    INTO v_maxtime
    FROM shift
    WHERE Shift_Code = v_ShiftCode;
    but getting error that is: Encountered the symbol INTO when expecting one of the following :=(%;
    am i doing any thing wrong.
    thanks

    APC wrote:
    The error you're getting is a syntax error. In this case because you've mangled the TO_CHAR syntax. Alas I cannot give you the correct version because I cannot unpick what you're trying to do with that statement.
    It would be easier if you expalined what business logic you're trying to implement instead of asking us to interpret a piece of shonky SQL.It's yet another of the OP's questions about how to do DATEs in Oracle (so many threads it can get very confusing - even though the OP has been asked to stick to one thread!).
    The code looks like it's based on the answer I gave here:
    How to get exact query of sql in oracle?
    but clearly he doesn't understand the basic syntax of Oracle or the datatypes he's using. Sometimes you just have to give up... (I know I have)

Maybe you are looking for

  • Cant use CCC to clone Snow Leapord mac to Mountain Lion mac

    hello all, I just bought a MacBook Pro (Mid 2012 not retina), and it came with Lion OSX. I recently installed Mountain Lion OS and it appears to be working welll except I am having trouble using a cloned external drive. I cloned my 2007 MacBook (Snow

  • Account shortname and admin name don't match-password is not accepted

    I had accidently changed my home name in the finder window. To fix this (so my files would show) I used NetInfo Manager to change the admin and user values. Now when I have tried to install a new program, the admin name does not show, and when trying

  • Looks like the size of the tabs/toolbar got smaller with V4. Is there a way to enlarge it?

    Is it my imagination, or did the tabs and toolbar in V4 get smaller and all scrunched up together? Makes it REALLY hard to see and hit the right spot for those of us that don't have 20-year-old eyes. Is there a way to change the display size of the t

  • X60 fingerprint reader driver

    Hello gurus, I've installed Win7 RC on my X60 and all is well. My colleague mentioned that Win7 has native support for use of a fingerprint reader, and I would like to try it out instead of using Lenovo's Client Security Solution. I have a clean Devi

  • My MBP shuts down unexpectedly

    My MBP (Mid 2012, HD Graphics 4000 1024MB, Software 10.9.5) turns off randomly. It has nothing to do with the battery. It turned off twice during a movie and shut down and a apple message appeared before starting up again. Any ideas?