Recordset with adOpenStatic and DISTINCT statement

I have a problem but i know to avoid it, but i don't understand why it's happening, so pls help!
I have something like that:
strSQL=     "SELECT DISTINCT field1 FROM table_name "
Set rs = Server.CreateObject("ADODB.RecordSet")
rs.CursorType = adOpenStatic
Call rs.Open (strSql, objConn)               
If Err.number<>0 Then
     Response.Write "..."
End If
If Not rs.EOF     Then
If rs("fields")=0 then
End If
End If
... and i'm getting: error: 3265 Item cannot be found in the collection corresponding to the requested
name or ordinal.
So if i make like this:
1. in stead of strSQL=     "SELECT DISTINCT field1 FROM table_name " i put strSQL= "SELECT DISTINCT field0, field1 FROM table_name " works
or
2. Instead of Call rs.Open (strSql, objConn) i put
Call rs.Open (strSql, objConn, adOpenReadOnly, adLockReadOnly) works
but like i said i dont understand why the first code dosen't work :( .. so pls explain
Ps. 1. First code works fine with Sql Server     
2. The same problem i have with strSQL=     "SELECT Count(*) AS field1 FROM table_name "

Hello Nimisha,
You said you received the cursor into your program.
If that means that your cursor has been opened before you received it then you can't change it's cursorType property.
Maybe, then, your cursor is still a moveForwardOnly.
I don't know how but you should try to set the cursorType property of your recordset before you receive the cursor.
Hope it will help.

Similar Messages

  • Use of the "updlock" hint with update and insert statements

    I have inherited some stored procedures and am trying to figure out why the developers decided to use the "updlock" hint on many of the update and insert statements. I have looked around everywhere and have found only one explanation of why "update...with
    (updlock)" can be useful, namely when a table has no clustered index:
    http://www.sqlnotes.info/2012/10/10/update-with-updlock/ I have found nothing yet that mentions why "insert into...with (updlock)" might be used. I understand why the hint
    might be useful on select statements in some cases, but if all of the tables have clustered indexes, is there any good reason to use it on update and insert statements?
    Thanks,
    Ron
    Ron Rice

    This form of deadlock error can occur on a table which has a clustered index.
    If you are doing updates on a table which has a clustered index and that table also has a nonclustered index and the nonclustered index is used to find the row to update you can see this type of deadlock.  For example create a table with a clustered
    primary key index and a nonclustered index by running
    Create Table Foo(PK int primary key identity, OtherKey varchar(10), OtherData int);
    go
    Insert Foo Default Values;
    go 10000
    Update Foo Set OtherKey = 'C' + Cast(PK As varchar(10))
    Create Unique Index FooIdx On Foo(OtherKey);
    That creates a table with 10000 rows, a clustered index and a nonclustered index.  Then run
    Begin Transaction
    Update Foo Set OtherData = 1 Where OtherKey = 'C5'
    That will use the FooIdx index to find the row that needs to be updated.  It will get a U lock on the index row in the FooIdx index, then an X lock on the row in the clustered index, update that row, then free the U lock on FooIdx, but keep the X lock
    on the row in the clustered index.  (There is other locking going on, but to simplify things, I'm only showing the locks that lead to the deadlock).
    Then in another window, run
    Begin Transaction
    Update Foo Set OtherData = 2 Where OtherKey = 'C5'
    This will get a U lock on the index row in the FooIdx index, then try to get an X lock on the row in the clustered index.  But that row is already exclusively locked, so this second window will wait holding a U lock on FooIdx row and is waiting for
    an X lock on the clustered index row.
    Now go back to the first window and run
    Update Foo Set OtherData = 3 Where OtherKey = 'C5'
    This will once again try to get the U lock on the FooIdx row, but it is blocked by the U lock the second window holds.  Of course the second window is blocked by the X lock on the clustered index row and you have a deadlock.
    All that said, I certainly do not routinely code my updates with UPDLOCK.  I try to design databases and write code so that deadlocks will be rare without holding excessive locks.  The more locks you hold and the longer you hold them, the more
    blocking you will get and the slower your system will run.  So I write code that if a deadlock exception occurs, it is properly handled.  Then if too many deadlocks occur, that is the time to go back to the code to see what changes are needed to
    decrease the number of deadlocks (one way to do that may be to get locks earlier and/or hold them longer. 
    But I wouldn't worry much about this form of deadlock.  It is, in my experience, vary rare.  I don't recall ever seeing it in a production environment.
    Tom

  • Help with TYPE and LIKE statements

    HI guys,
    I know this is really novice stuff, but I am a little confused.
    Can anyone please explain the exact difference between TYPE and like with the help of a program, to understand it.
    What situation would demand the use of each of the LIKE statement, since I can do all these things using the TYPE ?

    Hi Akhil,
    I summarized the info in SDN posts and SAP Help, to make it easier for you to understand. I also included some code snippets. Hope these prove to be helpful to you.
    The following is from SAP Help:
    The Additions TYPE and LIKE
    The additions TYPE type and LIKE dobj are used in various ABAP statements. The additions can have various meanings, depending on the syntax and context.
    ·        Definition of local types in a program
    ·        Declaration of data objects
    ·        Dynamic creation of data objects
    ·        Specification of the type of formal parameters in subroutines
    ·        Specification of the type of formal parameters in methods
    ·        Specification of the type of field symbols
    A known data type can be any of the following:
    ·        A predefined ABAP type to which you refer using the TYPE addition
    ·        An existing local data type in the program to which you refer using the TYPE addition
    ·        The data type of a local data object in the program to which you refer using the LIKE addition
    ·        A data type in the ABAP Dictionary to which you refer using the TYPE addition. To ensure compatibility with earlier releases, it is still possible to use the LIKE addition to refer to database tables and flat structures in the ABAP Dictionary. However, you should use the TYPE addition in new programs.
    The LIKE addition takes its technical attributes from a visible data object. As a rule, you can use LIKE to refer to any object that has been declared using DATA or a similar statement, and is visible in the current context.  The data object only has to have been declared. It is irrelevant whether the data object already exists in memory when you make the LIKE reference.
    ·        In principle, the local data objects in the same program are visible. As with local data types, there is a difference between local data objects in procedures and global data objects. Data objects defined in a procedure obscure other objects with the same name that are declared in the global declarations of the program.
    ·        You can also refer to the data objects of other visible ABAP programs. These might be, for example, the visible attributes of global classes in class pools. If a global class cl_lobal has a public instance attribute or static attribute attr, you can refer to it as follows in any ABAP program:
    DATA dref TYPE REF TO cl_global.
    DATA:  f1 LIKE cl_global=>attr,
           f2 LIKE dref->attr.
    You can access the technical properties of an instance attribute using the class name and a reference variable without first having to create an object. The properties of the attributes of a class are not instance-specific and belong to the static properties of the class.
    Example
    TYPES: BEGIN OF struct,
             number_1 TYPE i,
             number_2 TYPE p DECIMALS 2,
           END OF struct.
    DATA:  wa_struct TYPE struct,
           number    LIKE wa_struct-number_2,
           date      LIKE sy-datum,
           time      TYPE t,
           text      TYPE string,
           company   TYPE s_carr_id.
    This example declares variables with reference to the internal type STRUCT in the program, a component of an existing data object wa_struct, the predefined data object SY-DATUM, the predefined ABAP type t and STRING, and the data element S_CARR_ID from the ABAP Dictionary.
    The following info is from various posts:
    --> Type: It is used when userdefined object link with SAP system data type.
    Local types mask global types that have the same names. When typing the interface parameters or field symbols, a reference is also possible to generic types ANY, ANY TABLE,INDEX TABLE, TABLE or STANDARD TABLE, SORTED TABLE and HASHED TABLE.
    --> Like: It is when data object link with the other data object.
    --> TYPE, you assign datatype directly to the data object while declaring.
    --> LIKE,you assign the datatype of another object to the declaring data object. The datatype is referenced indirectly.
    you can refer to all visible data objects at the ABAP program's positon in question. Only the declaration of the data object must be known. In this case it is totally irrelevant whether the data object already exists physically in
    memory during the LIKE reference. Local data objects mask global data objects that have the same name.
    --> Type is a keyword used to refer to a data type whereas Like is a keyword used to copy the existing properties of already existing data object.
    Types: var1(20) type c.
    data: var2 type var1. ( type is used bcoz var1 is defined with TYPES and it
    does not occupy any memory spce.
    data: var3 like var2. ( like is used here bcoz var2 is defined with DATA
    so it does occupy space in memory ).
    data: material like mara-matnr. ( like is used here bcoz mara-matnr is stored in memory)
    --> Type refers the existing data type
    --> Like refers the existing data object
    Please Reward Points if any of the above points are helpful to you.
    Regards,
    Kalyan Chakravarthy

  • Query result different with profit and loss statement

    Hi all,
    I run query Sum(JDT1.Debit - JDT1.Credit), and then compare the query result with the profit and loss statement, and there is different.
    The difference is about 0.01.
    At SAP, the Decimal places is set to 2.
    I already checked the data, and their amount in 2 decimal.
    Do anyone know such problem and what kind of query must I use so the result can be compared with the profit and loss statement ?
    Thx.

    Riny, 
    I am glad you found the issue
    Suda

  • Issue with onWithForcePPR and components state

    Hi all!
    I have panelGroupLayout on my template, clientComponent="true", in javascript I change visibility, all is ok BUT when I go to other page, based on this template component visibility property is same as on previous page. How I can fix it?
    My script:
    AcPipeScripts.toggleSchedule = function (event) {
    var group = event.getSource().findComponent(AcPipeScripts.SCHEDULE_PANEL_ID);
    if (group) {
    group.setVisible(event.getNewValue());
    }

    Hi,
    tried to reproduce this with JDeveloper 11.1.2.2
       <context-param>
        <param-name>oracle.adf.view.rich.pprNavigation.OPTIONS</param-name>
        <param-value>onWithForcePPR</param-value>
      </context-param>And it worked and doesn't reproduce the isse
    Frank

  • Time variables with if and else statements for class script

    Hello, for an in class assignment to create a script using random generated answers im trying to get the script set up for different answers depending on the time of day here is what i have so far, in bold is my second time that i would like to have if the
    time is 6pm, the one that works right now is the one that is anything greater then 12pm and the one that is everything before 12pm the 6pm will not work:
    #Clear the Windows command console screen
    Clear-Host
    #Define the variables used in this script to collect player inputs
    $question = ""   #This variables will store the player's question
    $status = "Play"  #This variable will be used to control game termination
    $answer = 0  #This variable stores a randomly genrated number
    $time = (Get-Date).Hour  #This variable stores the current hour of the day
    #Display the game's opening screen
    Write-Host
    Write-Host
    Write-Host
    Write-Host
    Write-Host "               W E L C O M E   T O   T H E   W I N D O W S"
    Write-Host
    Write-Host
    Write-Host
    Write-Host "            P O W E R S H E L L   F O R T U N E   T E L L E R"
    Write-Host
    Write-Host
    Write-Host   
    Write-Host "                          By Zelandra"
    Write-Host
    Write-Host
    Write-Host
    Write-Host
    Write-Host
    Write-Host
    Write-Host
    Write-Host
    Write-Host
    Write-Host
    Write-Host " Press Enter to continue."
    #Pause script execution and wait for the player to press the Enter key
    Read-Host
    #Clear the Windows command console screen
    Clear-Host  
    #Provide the player with instructions
    Write-Host
    Write-Host " The fortune teller is a very busy and impatient mystic. Make"
    Write-Host 
    Write-Host " your questions brief and simple and only expect to receive"
    Write-Host
    Write-host " Yes / No styled answers."   
    Write-Host 
    Write-Host
    Write-Host
    Write-Host
    Write-Host
    Write-Host
    Write-Host
    Write-Host
    Write-Host
    Write-Host
    Write-Host
    Write-Host
    Write-Host
    Write-Host
    Write-Host
    Write-Host
    Write-Host
    Write-Host " Press Enter to continue."
    #Pause script execution and wait for the player to press the Enter key
    Read-Host
    #Continue game play until the player decides to stop
    while ($status -ne "Stop") {
      #Ask the player the first question
      while ($question -eq ""){
        Clear-Host  #Clear the Windows command console screen
        Write-Host
        $question = read-host " What is your question? "
      $question = ""  #Reset variable to a empty string
      #Retrieve a random number between 1 and 7
      $answer = Get-Random -minimum 1 -maximum 8
      #If it is the night the fortune teller will be a little more cranky 
      if ($time -gt 18) {
        Write-Host
        if ($answer -eq 1) { " Grrrr. The answer is NO, now let me get back to sleep!" }
        if ($answer -eq 2) { " Grrrr. The answer is !!!NEVER!!!" }
        if ($answer -eq 3) { " Grrrr. The answer is unclear, did you really think i would know?" }
        if ($answer -eq 4) { " Grrrr. The answer is sure whatever!" }
        if ($answer -eq 5) { " Grrrr. Even if i wanted to tell your fortune i wouldnt!" }
        if ($answer -eq 6) { " Grrrr. Look at the time, im busy SLEEPING!" }
        if ($answer -eq 7) { " Grrrr. Take whatever answer you want and leave me alone!" }
      #Select an answer based on the time and the random number
      #If it is the afternoon the fortune teller will be a little cranky
      if ($time -gt 12) {
        Write-Host
        if ($answer -eq 1) { " Grrrr. The answer is no!" }
        if ($answer -eq 2) { " Grrrr. The answer is never" }
        if ($answer -eq 3) { " Grrrr. The answer is unclear!" }
        if ($answer -eq 4) { " Grrrr. The answer is yes!" }
        if ($answer -eq 5) { " Grrrr. The answer is absolutely not!" }
        if ($answer -eq 6) { " Grrrr. The answer is unforseeable!" }
        if ($answer -eq 7) { " Grrrr. Im sorry could you repeat that?" }
      #If it is morning the fortune teller will be in a good mood
      else {
        Write-Host
        if ($answer -eq 1) { " Ah. The answer is yes!" }
        if ($answer -eq 2) { " Ah. The answer is Always" }
        if ($answer -eq 3) { " Ah. The answer is uncertain!" }
        if ($answer -eq 4) { " Ah. The answer is no!" }
        if ($answer -eq 5) { " Ah. The answer is there is a fair cha... OH LOOK A SQUIRREL!" }
        if ($answer -eq 6) { " Ah. I think you meant to ask something else!" }
        if ($answer -eq 7) { " Ah. Well it looks like your wish will be ready tonight!" }
      Write-Host
      Write-Host
      Write-Host
      Write-Host
      Write-Host
      Write-Host
      Write-Host
      Write-Host
      Write-Host
      Write-Host
      Write-Host
      Write-Host
      Write-Host
      Write-Host
      Write-Host
      Write-Host
      Write-Host
      Write-Host
      Write-Host
      Write-Host " Press Enter to continue."
      #Pause script execution and wait for the player to press the Enter key
      Read-Host
      #Clear the Windows command console screen
      Clear-host
      Write-Host
      #Prompt the player to continue or quit
      $reply = read-host " Press Enter to ask another question or type Q to quit."
      if ($reply -eq "q") { $status = "Stop" }
    #Clear the Windows command console screen
    Clear-Host
    #Provide the player with instructions
    Write-Host 
    Write-Host " Very well then. Please return again to get all your questions"
    Write-Host " answered." 
    Write-Host
    Write-Host 
    Write-Host
    Write-Host
    Write-Host
    Write-Host 
    Write-Host
    Write-Host
    Write-Host  
    Write-Host 
    Write-Host
    Write-Host
    Write-Host
    Write-Host
    Write-Host 
    Write-Host
    Write-Host
    Write-Host
    Write-Host
    Write-Host
    Write-Host " Press Enter to continue."
    #Pause script execution and wait for the player to press the Enter key
    Read-Host
    #Clear the Windows command console screen
    Clear-Host  
    Thanks again if anyone can provide help.

    Hi,
    Use -and in your afternoon if test.
    Don't retire TechNet! -
    (Don't give up yet - 12,950+ strong and growing)

  • CTAS with partitions and constraint statement, Is this possible?  Help!

    I'm trying to use CTAS to create a copy of one of our large tables to test the use of local indexs and partition pruning. Can anyone help me out here? Is this doable or should I go another route? I'm also rearranging the table to put the first column of my primary key as the first column of the table.
    Create table new_table,
    constraint pk_new_table primary key (seq_number,ssn,service_code)
    using index (create index PK_LI_new_table ON new_table (seq_number,ssn,service_code) LOCAL tablespace TS_LI_new_table)
    tablespace TS_NEW_TABLE
    PARTITION BY RANGE (SEQ_NUMBER)
    partition P197203 values less than (2) tablespace ts_new_table_197203,
    partition P200906 values less than (245) tablespace ts_new_table_200906
    AS SELECT (<new order of columns>) from <original_table>
    parallel enable row movement;
    output from statement:
    Create table new_table,
    Error at line 1:
    ORA-00922: missing or invalid option
    The asterisk is below the comma in the above error statement. Would I need to list out the new table columns and datatypes in the create table statement? Any help appreciated.

    Hello,
    CTAS will not replicate the structure of the source table.
    Your best option may be to:
    1. Create the empty table that you'll be populating, perhaps using the DBMS_METADATA package:
    set pagesize 5000
    set long 100000
    SELECT DBMS_METADATA.GET_DDL('TABLE','<your_table>','<owner>') FROM DUAL;2. Then INSERT direct-path into that table:
    INSERT /*+ APPEND */ INTO new_table (co1, col2, col3,... coln)
    SELECT col1, col2, col3,...
      FROM source_table;
    wolfeet wrote:Would I need to list out the new table columns and datatypes in the create table statement? And you can specify the order of the columns in the INSERT statement above.

  • Actuate to BIP Conversion Need Help with Sum and Distinct

    Hi,
    I am in the process of converting an Actuate report to BI Publisher .rtf format. Within the actuate report I have encountered the following code in one of the fields:
    Sum([ssCalc])Distinct([ssProfessional_Id])
    From what I understand this Actuate code is grouping by distinct ssProfessional_Id then taking the sum of the ssCalc field.
    In my .rtf template I have the following:
    <?for-each-group:ssSRA;./ssCIN?>
    <?ssCalc?>
    <?end for-each-group?>
    I need to convert the Actuate code into the place where I currently have <?ssCalc?> in my template but I have no idea how I can translate translate this. Does anyone have any suggestions?????
    Thanks,
    Fred

    Fred
    Can you post the XML, easier to help then
    Tim

  • Select distinct statement with various alias

    Hi everybody,
    I'm trying to put a select distinct statement in a query with two different alias for two different tables; like that:
    select distinct a.ma_name||'.'||a.ma_first_name d,
    a.ma_first_name||'.'||a.ma_name r
    from ma_main a, manager_liste b
    where (UPPER(b.manager_first_name||'.'||b.manager_name) = :APP_USER or
    (case when 'X'=:APP_USER or 'Y'=:APP_USER
    then 1
    else 0
    end) = 1)
    order by a.ma_name
    But it doesn't work. Can anybody help?
    Thx a lot!
    Jan

    hi,
    this is the error:
    1 error has occurred
    LOV query is invalid, a display and a return value are needed, the column names need to be different. If your query contains an in-line query, the first FROM clause in the SQL statement must not belong to the in-line query.
    and the table manager_liste and ma_main are varchar tables.
    how can i make it work, so that my select list with submit does only show distinct names. Because right now it shows each name about 10 times....

  • Customer Statement with opening and closing balances

    Dear Forum,
    The users want to generate the Customer Statement with opening and closing balances like the traditional one. The statement now generated gives the list of all open items as on date, but the users want the statement with opening balances as on the date of the begining of the range specified and the closing balance at the end of the period for which the statement is generated. Is there a way to generate the same from the system.
    Thanks for the help.
    Regards,

    Hi,
    SPRO> Financial Accounting (New) > Accounts Receivable and Accounts Payable > Customer Accounts > Line Items > Correspondence > Make and Check Settings for Correspondence
    You can use the program RFKORD10 with correspondance type SAP06 for your company code
    This program prints account statements and open items lists for customers and vendors in letter form. For account statements, all postings between two key dates, as well as the opening and closing balance, are listed.
    Regards,
    Gaurav

  • FI Customer Account Statement with Debit and Credit Columns

    Hi SAP Expert,
    We are using form (developed from T-code: SE71) to send customer account statment for only open items this is working fine.
    Now My wants customer account statement for all transactions but with debit and credit in a separate columns. is there any way we fulfill these kind of request?
    if any particular logic then let me know please.
    thanks in advance
    b/r
    prashant rane

    Dear Vivek,
    You logic is helpful can I apply this in SE71 form development?
    Below is my customer layout format
    Document # | Document Date | Reference | Debit Amt | Credit Amt |
    In bottom toal Debit / credit balance figure
    can I use any code/login is SE71 form or I will need to create any development report which involves user exit?
    I am looking for SE71 optios first
    thanks in advance
    Prashant Rane

  • Tried opening a file in library and it states can't open database with library name? It says Relaunch then will not open? and Blocks me completely from Aperture. I have to go to Finder to Rename it? I need this file how do I get it to open?

    Tried opening a file in library and it states can't open database with library name? It says Relaunch then will not open? and Blocks me completely from Aperture. I have to go to Finder to Rename it? I need this file how do I get it to open?

    Aftershotz,
    You're going to have to give a bit more information.
    What do you mean by "opening a file in library?"  There is no function of Aperture to open files -- you can open (switch) libraries.
    You'll have to be more specific about error messages, too.  Perhaps some screenshots would be useful to diagnose your problem.  "Can't open database with library name" is not enough detail about what Aperture is really telling you.
    nathan

  • Issue with TableAdapter Configuration Wizard and CASE statements

    I am having an issue with using any CASE statements in the select clause for the Table Adapter Configuration Wizard (TCW).  I can take any query without a CASE and it will run fine, but inserting any CASE statement in the Select such as:
    SELECT
    (CASE WHEN :ras_sort = 'D' THEN TO_CHAR(a.TRANS_DATE,'YYYYMMDD')
      WHEN :ras_sort = 'C' THEN  c.CLAIMDEP_NAME
      WHEN :ras_sort = 'A' THEN  TO_CHAR(a.ACCOUNT_NUMBER)
      END) sort1
    FROM xxxx
    causes the TCW to error with "error in list of function arguments, 'THEN' not recognized" and several other errors.  I have tried with and without parameters in the CASE and have tried both forms of the CASE statement.  I have tried multiple queries, all that run with no problem outside of TCW and ODP, but this seems to be a real issue
    Is this a known problem and are there any workarounds that will allow use of the TCW?
    Thanks,
    Dave

    Hi Ashish,
    perhaps you launch the Web service wizard from the wrong location (i.e. not selecting the SEI you want to use). Did you strictly follow the steps described in the <a href="http://help.sap.com/saphelp_nwce10/helpdata/en/44/f36fa8fd1d41aae10000000a114a6b/frameset.htm">documentation</a> for creating the web service?

  • Where clause with a combination of And and Or statements - Basic question

    Hi,
    I have a where clause with a combination of And and Or statements... May I know which one would run first
    Here is the sample
    WHERE SITE_NAME = 'Q' AND ET_NAME IN ('12', '15') AND TEST_DATE > DATE OR SITE_NAME = 'E' AND ET_NAME IN ('19', '20')
    can you please explain how this combination works
    Thanks in advance

    Hi,
    This reminds me of a great story. It's so good, it probably didn't really happen, but it's so good, I'm going to repeat it anyway.
    IBM once had an "executive apptitude test" that they would give to job applicants. There were some questions you might call general knowlege or trivia questions, and each question had a weight (for example, answering an unimportant queestion might score one point, an important question might be 5 points.) One of the questions was "What is the standard width of a mobile home?", and the weight of the question was -20: answering the question correctly did serious harm to your score. The reasoning was that the more you knew about mobile homes, the less likely you were to be their kind of executive.
    Now, as to your question, the correct answer is: I don't know. I don't want to know. Mixing ANDs and ORs without grouping them in parentheses is a really bad idea. Even if you get it right, it's going to confuse the next person who has to look at that code. Use parentheses to make sure the code is doing what you want it to do.
    If you really want to find out, it's documented in the SQL language manual. Look up "Operators, prcedence"
    http://docs.oracle.com/cd/E11882_01/server.112/e26088/operators001.htm#sthref815
    You can easily do an experiment, using scott.emp, or even dual, where
    WHERE  (x AND y)
    OR      zproduces different results from
    WHERE   x
    AND     (y OR z)

  • Need Help With SQL GROUP BY and DISTINCT

    I am working on a project and need to display the total of each order based on the order id. For instance I want to display the order id, customer id, order date, and then the extension price (ol_quantity * inv_price).
    I would then like a total displayed for order # 1 and then move on to order #2.
    Here is my SQL code :
    SELECT DISTINCT orders.o_id, customer.c_id, inv_price * ol_quantity
    FROM orders, customer, inventory, order_line
    GROUP BY orders.o_id, customer.c_id, inv_price, ol_quantity
    ORDER BY orders.o_id;
    When my code is run it displays the order id, customer id and inv_price * quantity (extension price) but no order total for the order number and a new group is not started when a new order number is started....they are all clumped together.
    Any help is greatly appreciated!!

    Hi,
    user12036843 wrote:
    I am working on a project and need to display the total of each order based on the order id. For instance I want to display the order id, customer id, order date, and then the extension price (ol_quantity * inv_price).
    I would then like a total displayed for order # 1 and then move on to order #2.
    Here is my SQL code :
    SELECT DISTINCT orders.o_id, customer.c_id, inv_price * ol_quantity
    FROM orders, customer, inventory, order_line
    GROUP BY orders.o_id, customer.c_id, inv_price, ol_quantity
    ORDER BY orders.o_id;
    When my code is run it displays the order id, customer id and inv_price * quantity (extension price) but no order total for the order number and a new group is not started when a new order number is started....they are all clumped together.
    Any help is greatly appreciated!!Sorry, it's unclear what you want.
    Whenever you post a question, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using.
    Do you want the output to contain one row for each row in the table, plus an extra row for each distinct order, showing something about the order as a whole (e.g., total inv_price or average extension_price)? If so, you need GROUP BY ROLLUP or GROUP BY GROUPING SETS .
    If you want one row of output for each row of the table, but you want to include something that reflects the group as a whole (again, e.g, total inv_prive or average extension_pcie), then you can us analytic functions. (Most of the aggregate functions, such as SUM and AVG have analytic counterparts that can get the same results without collapsing the result set down to one row per group.)
    Here's an example of how to use GROUP BY GROUPING SETS.
    Way we're interested in employees' salary and commission from the scott.emp table:
    SELECT       deptno
    ,       ename
    ,       sal
    ,       comm
    FROM       scott.emp
    ORDER BY  deptno
    ,            ename
    ;Output:
    `   DEPTNO ENAME             SAL       COMM
            10 CLARK            2450
            10 KING             5000
            10 MILLER           1300
            20 ADAMS            1100
            20 FORD             3000
            20 JONES            2975
            20 SCOTT            3000
            20 SMITH             800
            30 ALLEN            1600        300
            30 BLAKE            2850
            30 JAMES             950
            30 MARTIN           1250       1400
            30 TURNER           1500          0
            30 WARD             1250        500Now say we want to add the total income (sal + comm, or just sal if there is no comm) to each row, and also to add a row for each department showing the total sal, comm and income in that department, like this:
    `   DEPTNO ENAME             SAL       COMM     INCOME
            10 CLARK            2450                  2450
            10 KING             5000                  5000
            10 MILLER           1300                  1300
            10                  8750                  8750
            20 ADAMS            1100                  1100
            20 FORD             3000                  3000
            20 JONES            2975                  2975
            20 SCOTT            3000                  3000
            20 SMITH             800                   800
            20                 10875                 10875
            30 ALLEN            1600        300       1900
            30 BLAKE            2850                  2850
            30 JAMES             950                   950
            30 MARTIN           1250       1400       2650
            30 TURNER           1500          0       1500
            30 WARD             1250        500       1750
            30                  9400       2200      11600(This relies on the fact that ename is unique.) Getting those results is pretty easy, using GROUPING SETS:
    SELECT       deptno
    ,       ename
    ,       SUM (sal)          AS sal
    ,       SUM (comm)          AS comm
    ,       SUM ( sal
               + NVL (comm, 0)
               )               AS income
    FROM       scott.emp
    GROUP BY  GROUPING SETS ( (deptno)
                             , (deptno, ename)
    ORDER BY  deptno
    ,            ename
    ;Notice that we're displaying SUM (sal) on each row. Most of the rows in the output are "groups" consisting of only one row from the table, so the SUM (sa) for that goup will be the sal for the one row in the group.
    Edited by: Frank Kulash on Nov 23, 2011 2:03 PM
    Added GROUPING SET example

Maybe you are looking for

  • Error when Preview in Browser or Export in HTML

    I'm getting this error... Please HELP! Need to publish the site immediately.

  • Would you use Flash Builder Beta2 for production project?

    i am currently developing a project in Flash Builder beta2 with flex 4 sdk with the new spark components. But as i can see not all mx components have a spark equivalent and in my bin-debug folder there are spark_4.0.0.10485.swf 431,927  bytes rpc_4.0

  • Using Apple DVD PLayer...

    I can't seem to open my Video_TS file so that I can view my home movie before I burn a copy. In fact, my disk image file of the movie is inaccessible in the program (file name is pale grey shade under 'Open DVD Media'). Does anyone know how to remedy

  • "File" does not have "Import. Can't open Import Wizard

    "File" on the Mozilla Firefox screen has no "Import" necessary to open the Import Wizard. I can't import any info. from my former browser.

  • Thunderbolt in win7 64 bit OS

    I see promise has the pegasus disk drive that interfaces to macbook pro with thunderbolt, but it says mac os X. Anyone know if thunderbolt on promise pegasus would work in win7 64 bit OS? Only looking for JBOD (just a bunch of disks) vice raid. Thank