Select row between x and y

Hi,
;WITH CTE AS
( SELECT tblFuelCostDetails.TripId, tblFuelCostDetails.PurchaseDate, tblPetrolPumps.PumpName as Pump
FROM           tblPetrolPumps INNER JOIN
tblFuelCostDetails ON tblPetrolPumps.PumpId = tblFuelCostDetails.PumpId
SELECT distinct TripID, PurchaseDate,DENSE_RANK() OVER (ORDER BY TripID) AS RowNumber,
    STUFF((SELECT ', '+Pump FROM CTE P2 WHERE P1.TripID = P2.TripID AND P1.PurchaseDate = P2.PurchaseDate
    FOR XML PATH('')),1,1,'') AS Pump    
    FROM CTE P1   
This query output is,
TripID
PurchaseDate
RowNumber
Pump
73
1/15/2014
1
 N.R, Masranga
74
1/16/2014
2
 N.R
75
1/12/2014
3
JK
76
1/13/2014
4
YUJ
77
1/14/2014
5
UYI
How can i get RowNumber between 2 and 4

Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules (you did not). Temporal
data should use ISO-8601 formats (you failed this basic IT standard! Shame on you!). Code should be in Standard SQL as much as possible and not local dialect. 
Did you know that putting “tbl-” is such a bad coding practice it has name? You actually Tibbled! 
>> I am trying to load time dimension in a specific order <<
A table has no ordering by definition. Let me say that again, so you will hear this: A table has no ordering by definition. You have completely missed the foundations of RDBMS. 
Your code is also bad. Why did you rename “pump_name” (a valid data element name) to “pump” (vague and invalid)? Why do you think naming a CTE to “CTE” is informative? 
Why are you destroying First Normal Form with XML??? Are you smarter than Dr. Codd? I would fire you for this kind of sloppy coding. 
Do you know how rate SELECT DISTINCT is in a good schema? We usually use a key in the queries so there are not redundant rows. But since we have no DDL and no sample data, we cannot help you clean up this mess. Your query is simply this:
SELECT F.trip_nbr, F.purchase_date, P.pump_name 
  FROM Petrol_Pumps AS P, Fuel_Cost_Details AS F
 WHERE P.pump_nbr = F.pump_nbr;
Now pass the result set to a presentation layer, as per any tiered architecture. Since we have no logical rule for the subset you want, adding a DENSE_RANK() may not do what you want. Why order by trip_nbr? This is a tag number, not part of a sequence. 
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL

Similar Messages

  • Rows between 101 and 150

    Hi,
    I want the rows between 101 and 150 for all values
    Select * from MQ where rownum between 101 and 150
    In the above is query is not working.
    and I tried this query too ,It is also not working
    Select * from MQ where (select rownum from MQ were rownum between 101 and 150)
    Here I am getting only Rownum.
    Please help

    http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/pseudocolumns009.htm#SQLRF00255
    Select  *  from
        (select   rownum   my_rownum
                 , MQ.* 
           from MQ
    where my_rownum between 101 and 150

  • Urgent - I have written select query between loop and endloop, Ple help out

    Can any one help out me on this select query. I have written select query between loop and endloop. When I execute the program it will take too much time in this query. Please help me out. Its very urgent.
    LOOP AT l_i_invoices ASSIGNING <l_invoices>.
          CLEAR alv_wa.
          alv_wa-bukrs = <l_invoices>-bukrs.
          alv_wa-gsber = <l_invoices>-gsber.
          CLEAR l_instid.
          CONCATENATE <l_invoices>-belnr <l_invoices>-gjahr INTO l_instid.
          SELECT top_wi_id FROM sww_wi2obj INTO TABLE l_i_swwwihead
                  WHERE catid   = c_catid_business_object
                    AND instid  = l_instid
                    AND typeid  = c_typeid_invoice
                    AND removed = space
                    AND ( wi_rh_task = c_task_buyer_message
                       OR wi_rh_task = c_task_buyer_message2 ).
          IF sy-subrc = 0.
            <l_invoices>-flag = 'X'.
          ELSE.
            <l_invoices>-flag = ' '.
          ENDIF.
          MODIFY l_i_invoices FROM <l_invoices> TRANSPORTING flag
                                WHERE belnr = <l_invoices>-belnr
                                   AND gjahr = <l_invoices>-gjahr.
          APPEND alv_wa TO i_alv.
        ENDLOOP.
    Thanks in advance.

    Here is a way to solve this problem.
    Choose somewhere before this loop processing to use that select. Therefore, you'll need use FOR ALL ENTRIES <that_loop_table> clause, and in the WHERE condition you need to specify that same fields.
    This way, you will have an internal table with all data you'll need to check.
    Then, inside your loop statement, use the READ TABLE command with the clause WITH KEY field = value, to read that record and use the value found.
    Like this sample:
      SELECT bukrs lifnr umsks umskz augdt augbl zuonr gjahr belnr buzei
             waers xblnr blart gsber ebeln zfbdt zbd1t zlsch
      INTO TABLE tg_bsak
      FROM bsak
      FOR ALL ENTRIES IN tl_bkpf_sel
      WHERE bukrs EQ tl_bkpf_sel-bukrs AND
            lifnr IN s_lifnr AND
            augbl EQ tl_bkpf_sel-belnr.
    LOOP AT tg_bseg INTO wa_bseg.
        READ TABLE tg_bsak INTO wa_bsak WITH KEY bukrs = wa_bseg-bukrs
                                                 gjahr = wa_bseg-gjahr
                                                 belnr = wa_bseg-belnr
                                                 BINARY SEARCH.
    if sy-subrc = 0.
    * do something
    endif.
    ENDLOOP.

  • How to delete a selected row from datagrid and how to create a datagrid popup

    hi friends,
                  I am new to flex.i am doing a flex4 application,i need help for this.
                i am having a data grid with columns.i have two questions.
               Ques 1: when  i selected a partiuclar row from a datagrid and click delete button  means that record will delete from the datagrid and DTO from the cloud  tables also.
                Ques 2: when i save  the data grid values using save button means that data will store in  respective cloud DTO which is related to the datagrid,
                     My requirement is i am using a search button when i click the search  button it will show a datagrid that datagrid will contain the previous  datagrid datas which is saved in the cloud.
    REQUIREMENT example: first screen:           i am using with data grid 3 columns (Student Roll number ,Student Name,Student pecentage)---->save--->data will store in cloud DTO.
    Second screen:                search button ----> it need show  datagrid popup.it will have data which we saved in the first screen with same columns(Student Roll number ,Student Name,Student pecentage).
    This is my requirement.
    Any suggession welcome.
    Thanks in advance.
    B.Venkatesan

    Lets break the problem statement in multiple steps
    1. We need a way to know the selection on all rows.
    2. We need the association of the checkBox with the data
    The  solution is to use a arrayCollection/array that holds all the instances  created for checkbox.This collection should be a property of component  containing the datagrid. We need to use a custom component  implementation or inline ItemRenderer. The way you have used is called  dropinItemRenderer. Preferaly use custom component implementation and  add the instance to the arrayCollection at CreationComplete. Make sure  you use addItemAt so that you add the instance in the same row as the  data. To get rowIndex the custom Checkbox should implement  IDropInListItemRenderer. You could iterate this collection to check all  the instances that are checked.
    Note: This is the approach considering your dataprovider doesnt have a selection field.
    Nishant

  • How to delete a Selected row from datagrid and how to create a datagrid popup with saved values

    hi friends,
                  I am new to flex.i am doing a flex4 application,i need help for this.
                i am having a data grid with columns.i have two questions.
               Ques 1: when i selected a partiuclar row from a datagrid and click delete button means that record will delete from the datagrid and DTO from the cloud tables also.
                Ques 2: when i save the data grid values using save button means that data will store in respective cloud DTO which is related to the datagrid,
                    My requirement is i am using a search button when i click the search button it will show a datagrid that datagrid will contain the previous datagrid datas which is saved in the cloud.
    REQUIREMENT example: first screen: i am using with data grid 3 columns (Student Roll number ,Student Name,Student pecentage)---->save--->data will store in cloud DTO.
    Second screen: search button ----> it need show  datagrid popup.it will have data which we saved in the first screen with same columns(Student Roll number ,Student Name,Student pecentage).
    This is my requirement.
    Any suggession welcome.
    Thanks in advance.
    B.Venkatesan

    Lets break the problem statement in multiple steps
    1. We need a way to know the selection on all rows.
    2. We need the association of the checkBox with the data
    The  solution is to use a arrayCollection/array that holds all the instances  created for checkbox.This collection should be a property of component  containing the datagrid. We need to use a custom component  implementation or inline ItemRenderer. The way you have used is called  dropinItemRenderer. Preferaly use custom component implementation and  add the instance to the arrayCollection at CreationComplete. Make sure  you use addItemAt so that you add the instance in the same row as the  data. To get rowIndex the custom Checkbox should implement  IDropInListItemRenderer. You could iterate this collection to check all  the instances that are checked.
    Note: This is the approach considering your dataprovider doesnt have a selection field.
    Nishant

  • How can I select rows of cells and merge them vertically into one cell in each column?

    I'm working in CS4 and need to be able to select 2 to 6 rows of cells (with many columns) in a table and then merge the selected cells vertically into one cell in each column. A few cells in the chart will not need to merge so I must select the ones that do. I have almost 100 pages of charts with cells that need merged this way by Tuesday. Please help!
    Top chart example needs to change to the bottom example.
    Header 1
    Header 2
    Header 3
    Header 4
    Header 5
    Header 6
    100
    600
    300
    600
    20000
    120000
    2000
    500
    400
    50000
    10000
    5000
    3000
    200
    700
    67
    122
    600
    900
    100
    2
    7
    123
    1110
    Header 1
    Header 2
    Header 3
    Header 4
    Header 5
    Header 6
    100
    500
    200
    100
    600
    400
    700
    900
    300
    5000
    30000
    2
    600
    10000
    67
    7
    20000
    2000
    122
    123
    120000
    5000
    600
    1110

    SmartCellMerge may help you:
    http://www.indiscripts.com/post/2012/04/improve-the-way-you-merge-cells-in-indesign
    @+
    Marc

  • Select Row immediately previous and following a date range

    I have a query which returns two values within a given date range (colA, colB). This works great. However, I also need to return (in a separate query) the entries immediately previous and following this current date range (same two values).
    I am more familiar with MySQL where the query would include an "Order by date desc limit 1" for the row previous to the original query or "Order by date asc limit 1" for the row following the original query.
    What is the best way to return these rows within Oracle?

    Hi,
    This is an example of a Top-N Query, where you want to pick N items (N=1 in this case) from the top of an ordered list.
    This problem is a little trickier, because you want to pick from two lists, the rows before the specieifed date range (in descending order) and the rows after the range.
    The easiest way might be a UNION of two separate queries, using WHERE ROWNUM = 1 in each one.
    The solution below is easier to generalize, e.g. if you want the first and last row from each department.
    WITH
    e     AS
         SELECT     empno, ename, hiredate
         ,     ROW_NUMBER () OVER
              ( ORDER BY     CASE
                             WHEN hiredate < TO_DATE ( '01-JAN-1982'
                                            , 'DD-MON-YYYY'
                                            ) -- Start of date range
                             THEN hiredate
                        END
                        DESC     NULLS LAST
              ) AS pre_num
         ,     ROW_NUMBER () OVER
              ( ORDER BY     CASE
                             WHEN hiredate > TO_DATE     ( '31-DEC-1982'
                                            , 'DD-MON-YYYY'
                                            ) -- End of date range
                             THEN hiredate
                        END
              ) AS post_num
         FROM     scott.emp
    SELECT     empno, ename, hiredate
    FROM     e
    WHERE     pre_num          = 1
    OR     post_num     = 1
    ;Results (last hire before 1982 and first hire after 1982):
         EMPNO ENAME      HIREDATE
          7788 SCOTT      19-APR-87
          7900 JAMES      03-DEC-81

  • Select Rows between given dates

    CREATE TABLE #tblleavetransaction (EMPID INT, LeaveFromDate Date, LeaveTODate Date)
    INSERT INTO #tblleavetransaction
    SELECT 431, '01-02-2013', '01-04-2013'  --MM-DD-YYYY
    UNION ALL
    SELECT 431, '01-12-2013', '01-18-2013'
    UNION ALL
    SELECT 431, '01-02-2014', '01-04-2014'
    UNION ALL
    SELECT 431, '01-12-2014', '01-18-2014'
    UNION ALL
    SELECT 431, '01-27-2014', '02-07-2014'
    UNION ALL
    SELECT 431, '02-02-2014', '02-04-2014' 
    UNION ALL
    SELECT 431, '02-08-2014', '02-09-2014' 
    UNION ALL
    SELECT 431, '02-20-2014', '03-09-2014' 
    DECLARE @PassingFromParam DATE, @PassingToParam DATE
    1) While passing this parameter 
    SET @PassingFromParam = '2014-01-05' --YYYY-MM-DD
    SET @PassingToParam = '2014-01-29' --YYYY-MM-DD
    Result set should be like.
    Emid   LeaveFromDate             LeaveTODate 
    431           01-02-2014         01-04-2014
    431           01-12-2014          01-18-2014
    431           01-27-2014         01-29-2014  ---changed
    2) While passing this parameter 
    SET @PassingFromParam = '2014-02-02' --YYYY-MM-DD
    SET @PassingToParam = '2014-02-15' --YYYY-MM-DD
    Result set should be like.
    Emid   LeaveFromDate      LeaveTODate 
     431     02-02-2014          02-07-2014 ---changed 
    431      02-02-2014            02-04-2014
    431      02-08-2014             02-09-2014 
    3) While passing this parameter 
    SET @PassingFromParam = '2013-01-01' --YYYY-MM-DD
    SET @PassingToParam = '2014-12-1' --YYYY-MM-DD
    Result set should be like.
    Emid   LeaveFromDate      LeaveTODate 
     431   01-02-2013  01-04-2013
     431  01-12-2013  01-18-2013
     431  01-02-2014  01-04-2014
     431  01-12-2014  01-18-2014
     431  01-27-2014  02-07-2014 ---Here no change same record
     431  02-02-2014  02-04-2014 
     431  02-08-2014  02-09-2014 
     431  02-20-2014  03-09-2014 

    Check out your previous thread
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/03eab2f6-49f1-415b-bba1-1cddf75c35d3/all-records-between-given-startdate-and-enddate?forum=transactsql
    Thanks and regards, Rishabh K

  • Select Date between range and display

    Hello - i need some ideas to the following:
    I need to create a form to submit some information, with the
    date that form was submitted, to a database using php.
    Once the form is submitted i need to retrieve multiple rows
    from the database based on a selected date range, and display the
    information
    Question one - any ideas on the flow that i need
    question two - how do you think that i best record the date -
    given that i need to select a range later.
    question three - how do I select mutiple rows give a range of
    dates
    Thanks

    Hello - i need some ideas to the following:
    I need to create a form to submit some information, with the
    date that form was submitted, to a database using php.
    Once the form is submitted i need to retrieve multiple rows
    from the database based on a selected date range, and display the
    information
    Question one - any ideas on the flow that i need
    question two - how do you think that i best record the date -
    given that i need to select a range later.
    question three - how do I select mutiple rows give a range of
    dates
    Thanks

  • Difference in selection tools between CS3 and CS4?

    I have not used CS4 or 5. I read there are big differences from CS3 to CS4 with regards to making selections.
    How much different are the following tools in CS4 over CS3?
    - marquees
    - laso tools
    - magic wand
    - quick mask
    Thanks.

    The tools you mention have not changed noticeably.
    There are additional tools and refinements in later versions.

  • How do i get the data present in the selected row at run time in Multicolumn list box?

    Hi,
    I am using multicolumn list box with three columns and i am having OK button.
    If the user selects particular row and then press ok then that row datas(that 3 values) has to get update in the file.
    Can u tell me how to get that selected row values alone and also how to append the list box value at run time?
    Thanks
    Meenatchi

    You can simply use the Value property of the MLBox to get the row selected & wire it to the Delete from array function with the Itemnames of the MLBox as the Input & Output of the Delate from array function.
    See the attached VI.
    - Partha
    LabVIEW - Wires that catch bugs!
    Attachments:
    Dbl-click Row to get Data & Delete.vi ‏41 KB

  • How to select row automatically in matrix (exp:automatic select row no 2)?

    Hi
    example i fill matrix row no 1 - 3 in serial number selection form or else (from database data)
    and i want to automatic select row no 2
    and i really have a big problem to do this
    oQuant = edit text
    oColumn = column
    oForm = form
    here some of my code
    ====================================
    formID = pVal.FormUID
    Set oForm = SBO_Application.Forms(formID)
    Set oMatrix3 = oForm.Items.Item("5").Specific
    Set oColumn3(3) = oMatrix3.Columns.Item("19")
    Set oQuant(5) = oColumn3(3).Cells.Item(2).Specific
    =====================================
    i tried
    oMatrix3.SelectRow 2, True, False
    but it didn't work , it's said that not user defined item
    oQuant(5).Active = True
    it works but that not the select what i want
    pls some one help me
    i really need it right away
    Thanks

    Hi chetan
    Thank You for your reply and yes i didn't write selection mode for my matrix
    but when i tried both of these code it still didn't work (for information i'm using visual basic 6, so it has a different syntax about .net and VB6 - exp: for .net  oMatrix.selectrow(2,true,false) , for VB6 oMatrix.selectrow 2,true,false )
    oMatrix.SelectionMode = SAPbouiCOM.BoMatrixSelect.ms_Auto
    oMatrix.SelectRow 2, True, False
    oMatrix.SelectionMode = ms_Auto
    oMatrix.SelectRow 2, True, False
    is there any presiquities for selection mode ?? because I always have <b>warning</b> on oMatrix.selectionmode
    "<b>Item - the item is not user defined item</b>"
    Edit : it works when i created a form and select row no 2,  but it didn't work with serial number selection form which the form is already exist in SBO (serial number selection is the form after klik add button in good issue form)
    Thanks

  • Toggling between single and multiple selection in a table

    I am working on ADF faces. I need to switch between single and multiple selection in <af:table based on a button I select.
    I cannot use switcher or rendered property inside <af:table. Only the first one is rendering the second one is not rendering based on the switch
    <f:facet name="selection">
    <af:tableSelectMany autoSubmit="true"
    rendered="#{treeBean.multipleRows}"/>
    </f:facet>
    <f:facet name="selection">
    <af:tableSelectOne autoSubmit="true"
    rendered="#{treeBean.singleRows}"/>
    </f:facet>
    When I use inside the switcher, it doesn't like the parent.
    Any ideas would be greatly appreciated.
    Thanks,
    Vijay.

    I have probably misunderstood what your issue is. I do not know what your version of ADF faces is. Here is some sample code working with my version. Please check if your jdev has "rowSelection" attribute. If it has, please try my sampe code
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="1.2"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:afh="http://xmlns.oracle.com/adf/faces/html"
    xmlns:af="http://xmlns.oracle.com/adf/faces">
    <jsp:directive.page contentType="text/html;charset=utf-8"/>
    <f:view>
    <af:document title="tableSelectMany Demo">
    <af:form>
    <af:panelGroup layout="vertical">
    <af:messages/>
    <af:selectOneChoice value="#{sessionScope.tableSelection}"
    autoSubmit="true"
    id="selType"
    label="Selection Type">
    <af:selectItem label="Single" value="#{null}"/>
    <af:selectItem label="Multiple" value="#{true}"/>
    </af:selectOneChoice>
    <af:table summary="Periodic table"
    binding="#{tableActions.table}"
    partialTriggers="selType"
    rowSelection="#{sessionScope.tableSelection ? 'multiple' : 'single'}"
    value="#{periodicTable.tableData}" var="row" rows="10">
    <af:column>
    <f:facet name="header">
    <af:outputText value="Name"/>
    </f:facet>
    <af:outputText value="#{row.name}"/>
    </af:column>
    <af:column>
    <f:facet name="header">
    <af:outputText value="Symbol"/>
    </f:facet>
    <af:outputText value="#{row.symbol}"/>
    </af:column>
    <af:column>
    <f:facet name="header">
    <af:outputText value="Action Column"/>
    </f:facet>
    <af:commandButton immediate="true" text="Action"
    action="#{row.action}"/>
    </af:column>
    </af:table>
    </af:panelGroup>
    </af:form>
    </af:document>
    </f:view>
    </jsp:root>

  • Select where timestamp between date1 and date 2

    try a lot of variations but still dont work
    this was my last shot, then i come here ask for help
    the field DATAHORAS is timestamp
    data1 and dat2 will come from a form
    To_Date(S.DATAHORAS, 'dd/mm/yyyy hh24:mi:ss')
    Between Cast(To_Date(:data1) As TimeStamp) And Cast(To_Date(:data2) As TimeStamp)
    thanks in advanced

    No. You don't need to. But....
    Edit: I was originally using a stupid example using DUAL which was completely misleading - sorry.
    Originally I used the example below to show that you don't have to do an explicit conversion.
    Things will still work comparing timestamps and dates.
    SQL> select systimestamp, sysdate, sysdate+1
      2  from dual
      3  where systimestamp between sysdate and sysdate + 1;
    SYSTIMESTAMP                        SYSDATE              SYSDATE+1
    09-FEB-10 13.58.35.712017 +00:00    09-FEB-2010 13:58:35 10-FEB-2010 13:58:35But then I added an explain plan to show that implicit conversions were going on:
    1  explain plan for
      2  select systimestamp, sysdate, sysdate+1
      3  from dual
      4* where systimestamp between sysdate and sysdate + 1
    SQL> /
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 4192335797
    | Id  | Operation        | Name              | Rows  | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT |                   |     1 |     1   (0)| 00:00:01 |
    |*  1 |  FILTER          |                   |       |            |          |
    |   2 |   INDEX FULL SCAN| SYS_IOT_TOP_57625 |     1 |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    PLAN_TABLE_OUTPUT
       1 - filter(SYS_EXTRACT_UTC(SYSTIMESTAMP(6))<=SYS_EXTRACT_UTC(SYSDATE@
                  !+1) AND SYS_EXTRACT_UTC(SYSTIMESTAMP(6))>=SYS_EXTRACT_UTC(SYSDATE@!))
    15 rows selected.
    SQL>However, this example is misleading because it's not the same implicit conversion you get with a proper table with a timestamp column:
    SQL> create table t1
      2  (col1 timestamp);
    Table created.
    SQL> ed
    Wrote file afiedt.buf
      1   explain plan
      2   for
      3   select *
      4   from   t1
      5   where col1 between to_date('08-JAN-2010','DD-MON-YYYY')
      6*             and     to_date('09-JAN-2010','DD-MON-YYYY')
    SQL> /
    Explained.
    SQL>
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 3617692013
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      |     1 |    13 |     2   (0)| 00:00:01 |
    |*  1 |  TABLE ACCESS FULL| T1   |     1 |    13 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    PLAN_TABLE_OUTPUT
       1 - filter("COL1">=TIMESTAMP' 2010-01-08 00:00:00' AND
                  "COL1"<=TIMESTAMP' 2010-01-09 00:00:00')
    Note
       - dynamic sampling used for this statement
    18 rows selected.
    SQL>Which is really what you want.
    It has an implicit conversion on the date parameters and no implicit conversion on the column which would prevent index usage if there were an index.
    Interestingly if you explicitly convert the dates to a timestamp, then you can get an extra filter predicate comparing the two parameters:
    SQL> explain plan
      2  for
      3  select *
      4  from   t1
      5  where col1 between cast(to_date('08-JAN-2010','DD-MON-YYYY') as timestamp)
      6             and     cast(to_date('09-JAN-2010','DD-MON-YYYY') as timestamp);
    Explained.
    SQL>
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 3332582666
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |     1 |    13 |     2   (0)| 00:00:01 |
    |*  1 |  FILTER            |      |       |       |            |          |
    |*  2 |   TABLE ACCESS FULL| T1   |     1 |    13 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    PLAN_TABLE_OUTPUT
       1 - filter(CAST(TO_DATE(' 2010-01-08 00:00:00', 'syyyy-mm-dd
                  hh24:mi:ss') AS timestamp)<=CAST(TO_DATE(' 2010-01-09 00:00:00',
                  'syyyy-mm-dd hh24:mi:ss') AS timestamp))
       2 - filter("COL1">=CAST(TO_DATE(' 2010-01-08 00:00:00', 'syyyy-mm-dd
                  hh24:mi:ss') AS timestamp) AND "COL1"<=CAST(TO_DATE(' 2010-01-09
                  00:00:00', 'syyyy-mm-dd hh24:mi:ss') AS timestamp))
    Note
    PLAN_TABLE_OUTPUT
       - dynamic sampling used for this statement
    23 rows selected.oracle version 11.1.0.6
    Sorry about the mistakes in previous version of this reply.
    Edited by: DomBrooks on Feb 9, 2010 2:25 PM

  • Difference between SELECT .. INTO and INSERT.. SELECT

    Hi All,
    I am on SQL Server 2008 R2. I have a very basic question.
    What is the difference between SELECT ... INTO command and INSERT ... SELECT command, when inserting data into a tamp table or even a normal table? Or what is the difference between them in general?
    When should I use SELECT ... INTO and when should I use INSERT... SELECT ?
    Please guide.
    Thanks in advance

    Generally both are the same . There is some optimizations in case of heaps.When inserting into a heap, the storage engine needs to find free space for new rows. It keeps track
    of the last page on which a row was inserted, and if that page has space, it will insert on that page. If there is no space, it will have to look at the PFS pages to find space available, and if it cannot find space, it needs to allocate a new page. This can
    be pretty slow  so SQL Server has an optimization named minimally logging.. Instead of allocating one page at a time,it is used a mechanism which allocates upto 64 pages (8 extents)
    at a time, and keeps these pages in a cache, so that it allocates from that cache first.
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

Maybe you are looking for