Help with sql insert single quotes

String insert = "INSERT INTO users(firstName, lastName, emailAdd, password) VALUES("+ firstNameForm + "," + lastNameForm + "," + emailForm + "," + passwordForm + ")";
Statement stmt = conn.createStatement();
     int ResultSet = stmt.executeUpdate(insert);
I have that sql insert statment in my servlet the servlet compiles fine but does not insert into the users table, i have been told that it is something to do with single quotes in sql statement, can anybody help me out?

Or can i change my sql table is there a autonumber which would increase everytime this servlet runs?make your field autoincrement :-)
example
ALTER TABLE `users` CHANGE `user_id` `user_id` INT( 10 ) UNSIGNED DEFAULT '0' NOT NULL AUTO_INCREMENT To insert record in the table.
example:
you have a table test and got two fields,
id = (INT) autoincrement
name = VARCHAR / TEXT etc.
to insert data to the table test try something like this:
String SQLStatement = "INSERT INTO test";
SQLStatement += "(name)";
SQLStatement += " VALUES (?)";
statement = Conn.prepareStatement(SQLStatement);
statement.setString(1, "Duke");
statement.executeUpdate();
statement.close();
Conn.close();Note we dont provide the field for id on our sql statement since it is set as auto-increment ;-)
regards,
Message was edited by:
jie2ee

Similar Messages

  • Help with SQL insert

    Hi,
    Brand new to CF - using CF9. Have SQL Server 2005 database. Only one table. Using CF for frontend. Do not know proper syntax to get INSERT to work. Keep getting "Element XXXXXX is undefined in FORM."
    Database name is RAWH.
    Columns for insert are:
    startdate
    enddate
    TypeHrs
    NoOfHours
    projects
    justification
    Frontend has forms and fields which are:
    Form                                       Field (value)
    firstDates                                startdate
    firstDates                                enddate
    typHrs                                     TypeHrs
    noHrs                                      NoOfHours
    none                                        projects
    none                                        justification
    Do not know how to code for INSERT - have this for now - which obviously does not work:
    <cfquery name="RAWH" datasource="RAWH">
    INSERT INTO RAWH
    (startdate, enddate, TypeHrs, NoOfHours, projects, justification)
    VALUES
    (#Form.firstDates#, '#Form.startdate#', '#Form.enddate#', #Form.typHrs#, '#Form.TypeHrs#', #Form.noHrs#, '#Form.NoOfHours#')
    </cfquery>
    What am I doing wrong?
    Get this:
    Element FIRSTDATES is undefined in FORM.
    The error occurred in D:\ColdFusion9\wwwroot\RAWH1\RAWH1.cfm: line 5
    3 : (startdate, enddate, TypeHrs, NoOfHours, projects, justification)
    4 : VALUES
    5 : (#Form.firstDates#, '#Form.startdate#', '#Form.enddate#', #Form.typHrs#, '#Form.TypeHrs#', #Form.noHrs#, '#Form.NoOfHours#')
    6 : </cfquery>
    7 :
    Really appreciate any help - thank you. BTW - datasource is in CF Admin.
    John
    RAWH 
    Microsoft SQL Server 
    OK 

    Ian & Dan,
    Thanks. I added "<cfdump var="#form#">" and the result is "struct [empty]."
    I altered the form/input code thusly,
    <form id="beginDate" name="beginDate" onclick="function compareDate(); method="post"
                   style="width: 1px; height: 1px;">
              <td><input style="width: 70px" type="text" id="startdate" name="startdate" /></td>
            </form>
            <form id="endnDate" name="endDate" onclick="function compareDate(); method="post"
                   style="width: 1px; height: 1px;">
              <td><input style="width: 70px" type="text" id="enddate" name="enddate" /></td>
            </form>
    Should this be a cfform? I also made separate forms for startdate and enddate rather than one form for both.
    The cfquery is this:
    <cfquery name="RAWH" datasource="RAWH">
    INSERT INTO RAWH
    (startdate, enddate, TypeHrs, NoOfHours, projects, justification)
    VALUES
    (#Form.beginDate#, '#Form.startdate#', '#Form.endDate#', '#Form.enddate#', #Form.typHrs#, '#Form.TypeHrs#', #Form.noHrs#, '#Form.NoOfHours#', 'projects', 'justification')
    </cfquery>
    Still the same result -
    Element BEGINDATE is undefined in FORM.
    The error occurred in D:\ColdFusion9\wwwroot\RAWH1\RAWH1.cfm: line 7
    5 : (startdate, enddate, TypeHrs, NoOfHours, projects, justification)
    6 : VALUES
    7 : (#Form.beginDate#, '#Form.startdate#', '#Form.endDate#', '#Form.enddate#', #Form.typHrs#, '#Form.TypeHrs#', #Form.noHrs#, '#Form.NoOfHours#', 'projects', 'justification')
    8 : </cfquery>
    9 :
    What am I doing wrong?
    Dan - you said that I do not have a form until I submit one - I get this error by opening the web page (F12). There is no onsubmit coding done.
    Sorry guys, I am lost with this.
    Thank you,
    John

  • Need help with SQL Query with Inline View + Group by

    Hello Gurus,
    I would really appreciate your time and effort regarding this query. I have the following data set.
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
    1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
    Please Ignore '----', added it for clarity
    I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
    The query should return the following data set
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
    The following is my query. I am kind of lost.
    select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
    from (
    select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
    from INVOICE
    group by sequence_id,check_date, check_number, invoice_number, vendor_number
    ) A, INVOICE B
    where A.sequence_id = B.sequence_id
    Thanks,
    Nick

    It looks like it is a duplicate thread - correct me if i'm wrong in this case ->
    Need help with SQL Query with Inline View + Group by
    Regards.
    Satyaki De.

  • Problem in insertion with string containing   ' (single quote)

    i have a text field in jsp.
    when i submit the content need to be inserted/updated.
    when the text field contains character's with single quote( ' )..
    i am unable to insert/update values in database..
    where as if the text field contains characters without single quote..there is no problem in Database insertion/updation.
    i am using create statement .. and oracle database..
    can any one help ...

    The usual answer for this in the JDBC forum (where this should have been posted because it's completely about JDBC) is to use a PreparedStatement.

  • To insert single quote in a varchar2 field

    hi guys,
    i am facing a simple problem, can any one of you help me in this regard. the problem is i am unable to insert a single quote in a varchar2 field like
    SQL> DESC EMP
    Name Null? Type
    EMPNO NOT NULL NUMBER(4)
    ENAME VARCHAR2(10)
    JOB VARCHAR2(9)
    MGR NUMBER(4)
    HIREDATE DATE
    SAL NUMBER(7,2)
    COMM NUMBER(7,2)
    DEPTNO NUMBER(2)
    SQL> INSERT INTO EMP (EMPNO, ENAME) VALUES (100, 'Mc'Aure') ;
    ERROR:
    ORA-01756: quoted string not properly terminated
    oracle takes ' as the delimiters for identifying the word. in my case the name itself contains a single quote which is to be inserted. how to insert the single quote
    i want to insert it from asp coding and also from sql plus 8.0.
    advanced thanks
    ananth

    If you use a ' in a varchar2, it must be marked with a second '.
    In your case:
    SQL> INSERT INTO EMP (EMPNO, ENAME) VALUES
    (100, 'Mc''Aure') ;
    null

  • JDBC insert single quote ???

    Hi,
    I want to insert a string which could contain a single quote ( ' ) into my database . But if this is the case, the regular insert command fails, since the single quote from the string collides with the ones from the command. What can I do???

    Try placing an escape char "\".
    So its like:
    String s="Sachin\'s page";
    If ur using it in xml use:
    &apos; to replace '.
    Hope this helps.
    Sachin

  • Sql insert single qoute ' problem

    I have problem when insert string that hv single quote.
    Can anyone help me on this...
    query = "INSERT INTO lexicon VALUES ( " + id + ", '" + lex + "')";
    s.executeUpdate(query);where lex is ambassador's.
    Below is the error:
    java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's')' at line 1

    Based on your coding I assume that lex is a string variable holding the value ambassador's. So that your query variable would be like this
    INSERT INTO lexicon VALUES ( 123 , 'ambassador's' )
    did you notice that your second value does not closed properly. to resolve this try to suppress the codes which is inside your lex value. Lets assign
    lex = "ambassador''s"; //two single quotes between r and s

  • How to insert single quote in to the table

    Pl help me out in how to insert the single quote ie ' into the table. If there is no other way, i will go for some other alternative
    Regards,
    Basavaraju

    SQL> desc varchar2_test
    Name                                      Null?    Type
    TEXT                                               VARCHAR2(4000)
    SQL> insert into varchar2_test values ('''ABCDEFGHIJ''');
    1 row created.
    SQL> select * from varchar2_test;
    TEXT
    'ABCDEFGHIJ'Thanks,
    BB

  • Need help with SQL*Loader not working

    Hi all,
    I am trying to run SQL*Loader on Oracle 10g UNIX platform (Red Hat Linux) with below command:
    sqlldr userid='ldm/password' control=issue.ctl bad=issue.bad discard=issue.txt direct=true log=issue.log
    And get below errors:
    SQL*Loader-128: unable to begin a session
    ORA-01034: ORACLE not available
    ORA-27101: shared memory realm does not exist
    Linux-x86_64 Error: 2: No such file or directory
    Can anyone help me out with this problem that I am having with SQL*Loader? Thanks!
    Ben Prusinski

    Hi Frank,
    More progress, I exported the ORACLE_SID and tried again but now have new errors! We are trying to load an Excel CSV file into a new table on our Oracle 10g database. I created the new table in Oracle and loaded with SQL*Loader with below problems.
    $ export ORACLE_SID=PROD
    $ sqlldr 'ldm/password@PROD' control=prod.ctl log=issue.log bad=bad.log discard=discard.log
    SQL*Loader: Release 10.2.0.1.0 - Production on Tue May 23 11:04:28 2006
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    SQL*Loader: Release 10.2.0.1.0 - Production on Tue May 23 11:04:28 2006
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Control File: prod.ctl
    Data File: prod.csv
    Bad File: bad.log
    Discard File: discard.log
    (Allow all discards)
    Number to load: ALL
    Number to skip: 0
    Errors allowed: 50
    Bind array: 64 rows, maximum of 256000 bytes
    Continuation: none specified
    Path used: Conventional
    Table TESTLD, loaded from every logical record.
    Insert option in effect for this table: REPLACE
    Column Name Position Len Term Encl Datatype
    ISSUE_KEY FIRST * , CHARACTER
    TIME_DIM_KEY NEXT * , CHARACTER
    PRODUCT_CATEGORY_KEY NEXT * , CHARACTER
    PRODUCT_KEY NEXT * , CHARACTER
    SALES_CHANNEL_DIM_KEY NEXT * , CHARACTER
    TIME_OF_DAY_DIM_KEY NEXT * , CHARACTER
    ACCOUNT_DIM_KEY NEXT * , CHARACTER
    ESN_KEY NEXT * , CHARACTER
    DISCOUNT_DIM_KEY NEXT * , CHARACTER
    INVOICE_NUMBER NEXT * , CHARACTER
    ISSUE_QTY NEXT * , CHARACTER
    GROSS_PRICE NEXT * , CHARACTER
    DISCOUNT_AMT NEXT * , CHARACTER
    NET_PRICE NEXT * , CHARACTER
    COST NEXT * , CHARACTER
    SALES_GEOGRAPHY_DIM_KEY NEXT * , CHARACTER
    value used for ROWS parameter changed from 64 to 62
    Record 1: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 2: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 3: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 4: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 5: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 6: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 7: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 8: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 9: Rejected - Error on table ISSUE_FACT_TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 10: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 11: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 12: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 13: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 14: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 15: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 16: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 17: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 18: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 19: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 20: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 21: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 22: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 23: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 24: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    Record 39: Rejected - Error on table TESTLD, column DISCOUNT_AMT.
    Column not found before end of logical record (use TRAILING NULLCOLS)
    MAXIMUM ERROR COUNT EXCEEDED - Above statistics reflect partial run.
    Table TESTLD:
    0 Rows successfully loaded.
    51 Rows not loaded due to data errors.
    0 Rows not loaded because all WHEN clauses were failed.
    0 Rows not loaded because all fields were null.
    Space allocated for bind array: 255936 bytes(62 rows)
    Read buffer bytes: 1048576
    Total logical records skipped: 0
    Total logical records read: 51
    Total logical records rejected: 51
    Total logical records discarded: 0
    Run began on Tue May 23 11:04:28 2006
    Run ended on Tue May 23 11:04:28 2006
    Elapsed time was: 00:00:00.14
    CPU time was: 00:00:00.01
    [oracle@casanbdb11 sql_loader]$
    Here is the control file:
    LOAD DATA
    INFILE issue_fact.csv
    REPLACE
    INTO TABLE TESTLD
    FIELDS TERMINATED BY ','
    ISSUE_KEY,
    TIME_DIM_KEY,
    PRODUCT_CATEGORY_KEY,
    PRODUCT_KEY,
    SALES_CHANNEL_DIM_KEY,
    TIME_OF_DAY_DIM_KEY,
    ACCOUNT_DIM_KEY,
    ESN_KEY,
    DISCOUNT_DIM_KEY,
    INVOICE_NUMBER,
    ISSUE_QTY,
    GROSS_PRICE,
    DISCOUNT_AMT,
    NET_PRICE,
    COST,
    SALES_GEOGRAPHY_DIM_KEY
    )

  • Insert single quote into the table

    Hi
    I have to insert values into a column that are retrieved by a select query on another table.
    The values inserted have single quotes (').
    Does anybody know how to do it?
    Thanks in advance

    If you get from one table and then insert in the other there shouldn't be any problem at all.
    SQL> create table blah_one as
      2  select 'Radha''s Sarma' col from dual
      3  /
    Table created.
    SQL> select * from blah_one
      2  /
    COL
    Radha's Sarma
    SQL> create table blah_two as
      2* select col from blah_one
    SQL> /
    Table created.
    SQL> select * from blah_two
      2  /
    COL
    Radha's Sarma
    SQL>Cheers
    Sarma.

  • To insert single quotes

    Hi
    All,
    Oracle 10.2.0.3
    AIX 5.3
    I have following query
    select 'ALTER DATABASE RENAME FILE ' || name || ' TO /u44/ORACLE/CMS' || substr(name,16) as move_datafile from v$datafile where name like '/u41%';
    Now, I want to type ALTER DATABASE RENAME FILE with single quotes. In other words I want to type string with single quotes. How can I achieve this?
    Thanks,
    Vishal

    Since you have Oracle 10G, you can use the new quote notation:
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/fundamentals.htm#i38404
    Examples, sorry about the orthographic faults:
    SQL> select q'"this it's a test of data's string"' from dual;
    Q'"THISIT'SATESTOFDATA'SSTRING"'
    this it's a test of data's string
    SQL> select q'/ this it's another's test of quotes isn't /' from dual;
    Q'/THISIT'SANOTHER'STESTOFQUOTESISN'T/'
    this it's another's test of quotes isn't

  • Looking for some help with building insert statements...

    Hi, I am using some sql to build some insert statements for me to update a set of tables in our qa environments. The scripts that I have created were working great until someone added a column to some of the tables in the qa env which in turn makes my scripts break because I was simply building the statment to do someting like this...
    insert into dest_table (select * from source_table@dblink);
    But now when the coumns in the tables do not match it breaks...
    This is the dynamic create script I use, can anyone help or suggest a better way to be able to build update statements update to qa tables when the columns are mismatched?
    spool insert.sql
    select
    'insert into ' || table_name || ' (select * from ' || table_name || '@prod );' || chr(10) || ' commit;'
    from user_tables
    where table_name in
    (select * from refresh_tablesl)
    any help is greatly appreciated,
    Thanks.

    See my reply to your duplicate post
    looking for help building dynamic insert statements...

  • Where to find help with SQL Developer installation?

    Hi,
    I just want to try out SQL Developer and compare its capabilities to TOAD's. Unfortunately, I am not PC software savvy and now am stuck with a SQL Developer (sqldeveloper-1.2.2998) installation problem. When I clicked on the .exe file, I got a blank SQL Developer screen - there is nothing in the screen except a heading that reads 'Oracle SQL Developer'...
    Does anyone know of a blog or a site that I can get some help with problems like mine?
    Any help is much appreciated!

    Hi,
    SQL Developer forum link:
    "http://forums.oracle.com/forums/forum.jspa?forumID=260"
    There are 2 versions of SQL Developer, with/without JRE.
    Try out the full install version with JRE.
    HTH
    Zack

  • Help with the insert table/form tool in BIP 10.1.3.2.1

    Hi, I'm trying to use the insert table/form tool in BIP, and running into some issues that I don't understand. First off, my data coming in looks like this (left column of tool):
    Rowset
    --- Row
    ------ Customer ID
    ------ Customer Name
    ------ Customer City
    ------ Product
    ------ Amount Sold
    I would like the output to do the following:
    a) have one page per customer. Customer should be determined by customer ID, and has attributes of customer ID, customer Name, Customer City
    b) Show a table of all products and the total Amount Sold by product for that customer
    c) Give a "grand total" for the customer
    Can someone help with the steps needed to do this? I've tried several variations of the following without much luck:
    1) Added Rowset and all children to the "Template" pane
    2) Clicked on the "Row" group, and set Grouping = Customer ID, with a break of "New page per Element"
    3) Clicked on the newly created (from step 2) Cust ID group, and set it to group by Product
    4) Moved "amount sold" to be at same level as Product
    5) Moved all of the customer attributes (name, address, etc.) to be at same level as Cust ID
    6) On the Cust ID level, set the style to table
    7) on row and rowset levels, set style to free form
    This seems to be VERY close, except that it isn't creating a total amount for the sum of all products purchased by a customer. What do I need to do inside the tool to get a total per customer to show up?
    Thanks in advance!
    Scott
    p.s. the final hierarchy in the template window looks like this:
    Rowset (style = freeform, no grouping/sort by/breaks)
    --- Row (style = freeform, group by customer ID, break new page per element)
    ------ Customer ID (style = table, group by product, no breaks)
    --------- Product (nothing special)
    --------- Amount Sold (calc for grouping = SUM)
    ------ Customer Name (nothing special)
    ------ Customer City (nothing special)
    Thanks very much for the help!
    Scott

    To anyone else who sees this post, the answer is to do the following. Insert the Amount Sold field using the "Insert Field" tool, and set the function to sum, with the grouping checkbox turned on.
    Thanks,
    Scott

  • Please help with SQL amount calulation

    -- Results
    with t as ( 
    select 'P11877' Mstr_Program,   1 Year_of_study, 'BUSI1490' program_module,  20 no_of_stud,    1 rank,   30 program_credits,  30 cumm_credits   from dual union all
    select 'P11877',                1,              'COMP1365',                 20,               2,        30,                  60               from dual union all
    select 'P11877',                1,              'BUSI1375',                 20,               3,        30,                  90               from dual union all
    select 'P11877',                1,              'COMP1363',                 20,               4,        30,                  120              from dual union all
    select 'P11877',                2,              'MARK1174',                 8,                1,        30,                  30               from dual union all
    select 'P11877',                2,              'FINA1068',                 8,                2,        15,                  45               from dual union all
    select 'P11877',                2,              'INDU1062',                 8,                3,        30,                  75               from dual union all
    select 'P11877',                2,              'BUSI1329',                 8,                4,        15,                  90               from dual union all
    select 'P11877',                2,              'MARK1138',                 8,                5,        30,                  120              from dual)
    select * from t;-- Each MSTR_PROGRAM can have 1 or many program_module
    -- MSTR_PROGRAM's can run for 1 or 2 years (case above is two years) so some modules run in year 1 and some in year 2
    -- NO_OF_STUD is the number of students on the module
    -- RANK basically ranks the modules by the number of students on them grouped by program and year
    -- e.g.row_number() OVER (PARTITION BY Mstr_Program, Year_of_study) ORDER BY COUNT(STUDENT_ID) DESC) rank
    -- PROGRAM_CREDITS: each module has a fixed number of credits
    -- CUMM_CREDITS: Increments the credit count of modules
    -- SUM(program_credits * 10) OVER (PARTITION BY Mstr_Program, Year_of_study
    -- ORDER BY count(STUDENT_ID) desc ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) cumm_credits
    -- I want to trim of any modules once the CUM_CREDITS hits 120. As seen above. I achieve this by wrapping the main query is another SELECT then LIMIT
    -- that WHERE cum_credit <=120.
    -- But what I need is:
    -- In some cases the the cumm_credit maybe on lets say 90credits then the next module is worth 40 credits. This next module will not show as it
    -- will be greater than 120 credits, so i need to pro-rata it:
    -- So if credit_count > 120, then the last module is counted pro-rata as follows: 1- ((credit count - 120) / credits from last module
    -- Can anyone help with how I can incorporate this into my current code: The SELECT portion of the Original SQL is below: I simplified column names
    -- e.t.c in the above so they wont be the same
    SELECT * FROM (
         SELECT
               ,SR_PROGRAM Mstr_Program
               ,DECODE (SORLCUR_YEAR, 1, 1,
                                      2, 2,
                                      3, 3,
                                      4, 3, SR_YEAR) year_of_study
               ,SCT_SUBJ_CODE||SCT_CRSE_NUMB program_module
               ,COUNT(student_ID)                    no_of_stud
               ,row_number() OVER (PARTITION BY sr_program,
                                            DECODE (sr_year, 1, 1,
                                                                  2, 2,
                                                                  3, 3,
                                                                  4, 3, SR_YEAR) ORDER BY COUNT(student_id) DESC, scbcrse_title asc) rank
               ,(SCT_CREDIT_HRS * 10) program_credits
               ,SUM(SCT_CREDIT_HRS * 10) OVER (PARTITION BY sr_program, DECODE (sorlcur_year, 1, 1,
                                                                                                       2, 2,
                                                                                                       3, 3,
                                                                                                       4, 3, SR_YEAR)
                                                    ORDER BY count(student_id) desc ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) cumm_credits
    WHERE cumm_credit <=120
    ORDER BY Mstr_Program, YEAR_OF_STUDY, RANK asc;

    Maybe
    SELECT Mstr_Program,year_of_study,program_module,no_of_stud,rank,program_credits old_program_credits,cumm_credits old_cumm_credits,
           case when cumm_credits > 120
                then program_credits - cumm_credits + 120
                else program_credits
           end new_program_credits,
           case when cumm_credits > 120
                then 120
                else cumm_credits
           end new_cumm_credits
      FROM (SELECT SR_PROGRAM Mstr_Program,
                   DECODE(SORLCUR_YEAR,1,1,2,2,3,3,4,3,SR_YEAR) year_of_study,
                   SCT_SUBJ_CODE||SCT_CRSE_NUMB program_module,
                   COUNT(student_ID) no_of_stud,
                   row_number() OVER (PARTITION BY sr_program,DECODE(sr_year,1,1,2,2,3,3,4,3,SR_YEAR)
                                          ORDER BY COUNT(student_id) DESC,scbcrse_title) rank,
                   10 * SCT_CREDIT_HRS program_credits,
                   10 * SUM(SCT_CREDIT_HRS) OVER (PARTITION BY sr_program,DECODE(sorlcur_year,1,1,2,2,3,3,4,3,SR_YEAR)
                                                      ORDER BY count(student_id) desc
                                                  ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) cumm_credits
    WHERE 0 <= case when cumm_credits > 120
                     then program_credits - cumm_credits + 120
                     else program_credits
                end
    ORDER BY Mstr_Program,YEAR_OF_STUDY,RANKRegards
    Etbin
    Edited by: Etbin on 16.12.2011 8:50
    with
    t as   /* simulating the result achieved */
    (select 'P11877' Mstr_Program,1 Year_of_study, 'BUSI1490' program_module,20 no_of_stud,1 rank,30 program_credits,30 cumm_credits from dual union all
    select 'P11877',             1,               'COMP1365',               20,           2,     40,                70              from dual union all
    select 'P11877',             1,               'BUSI1375',               20,           3,     30,                100             from dual union all
    select 'P11877',             1,               'COMP1363',               20,           4,     40,                140             from dual union all
    select 'P11877',             2,               'MARK1174',               8,            1,     30,                30              from dual union all
    select 'P11877',             2,               'FINA1068',               8,            2,     50,                80              from dual union all
    select 'P11877',             2,               'INDU1062',               8,            3,     30,                110             from dual union all
    select 'P11877',             2,               'BUSI1329',               8,            4,     50,                160             from dual union all
    select 'P11877',             2,               'MARK1138',               8,            5,     30,                190             from dual
    select Mstr_Program,Year_of_study,program_module,no_of_stud,rank,program_credits old_credits,cumm_credits old_cumm,
           case when cumm_credits > 120
                then program_credits - cumm_credits + 120
                else program_credits
           end new_program_credits,
           case when cumm_credits > 120
                then 120
                else cumm_credits
           end new_cumm_credits
      from t
    where 0 <= case when cumm_credits > 120
                     then program_credits - cumm_credits + 120
                     else program_credits
                end

Maybe you are looking for

  • Sy-Batch Problem

    Iam using a BDC for F-32 transaction and when I run in foregreound it runs good but when I run in back ground it gives out an error meesage ..The message number is NA-00344 saying that No batch input for screen SAPDF05X 3100.. ..Can anyone please tel

  • Error message 13005 when trying to open iTunes

    Hi, my iTunes updated over the weekend and now will not open. I get the following error message. "The iTunes application could not be opened. An unkown error occurred (13005)." Have completly uninstalled iTunes and re installed. Have uninstalled and

  • KNA1 Mass Maintenance with a BADI implemented.

    Hi Everyone, We have implemented a Customer Master BADI to maintain some additional KNA1 and KNVV fields. when we execute XD99 to mass maintain an SAP field (KNVV-AUFSD)we receive an error "Enter a valid value". When I debug I dsicover that it is att

  • Photoshop Album SE 3.0: An eMail anhängen

    Die oben beschriebene Funktion führt bei mir zur Microsoft Outlook-Meldung: "Der Vorgang konnte wegen Netz- oder Kommunikationsproblemen nicht ausgeführt werden ..." Danach bricht die Funktion ab. Wer weiß Rat ? Danke !

  • What External Hard Drive to Buy, any Suggestions.

    Hi all, i need an external hard drive. Easily answered i hear you say, here's where it gets harder. I dont want to buy a case and a drive and then build it, i want to buy it off the shelf. I need.................... Firewire Oxford chipset 300-500 GB