I don't want to write too much code is there a different way of doing this

I am writing a precedure to check on the max test scores for different codes ('S01','S02'.S03') --there are more
then I need to insert the table if the record with the best score does not exists for example for b.sortest_tesc_code = 'BSV', I am writing a cursor
for each code (.sortest_tesc_code = 'S01') is there a way to do this different? so I cant do something like a.sortest_tesc_code in ('S01','S02'.S03') and store in a
variable then insert, the problem is that you can have a student that have only one test other that have two etc..etc.. is not consistent, also If the b.sortest_tesc_code = 'BSV') is already in the table I don't do an insert I will have to do an update if the sortest_test_score is greater since the student can submit scores more than once... In another words check if the record exists( b.sortest_tesc_code = 'BSV') if is there compare with the new max score and if the new max score is greater then update.. If the score (by code) is not in the table insert
Hope this is clear, this is what I have, I now it will work but it will be too much code..check for exists and not exists in two different precedures..
Thank you
CURSOR get_the_max_scores_S01_cur IS
            SELECT
             sortest_pidm, a.sortest_test_score, a.sortest_tesc_code,
             a.sortest_test_date,a.sortest_equiv_ind
            FROM
            saturn.spriden, saturn.sortest a, saturn.stvtesc
           WHERE 
           a.sortest_pidm = spriden_pidm
          AND stvtesc_code = a.sortest_tesc_code
          AND spriden_change_ind IS NULL
       -----and   a.sortest_tesc_code in ('S01','S02'.S03')
       AND a.sortest_tesc_code = 'S01'
       --and spriden_id = p_student_id  --
       ---for test purposes
       AND sortest_pidm = 133999 ----THE WILL BE A PARAMETER
       AND a.sortest_test_score =
              (SELECT MAX (b.sortest_test_score)
                 FROM saturn.sortest b
                WHERE a.sortest_tesc_code = b.sortest_tesc_code
                      AND a.sortest_pidm = b.sortest_pidm)
                            AND NOT EXISTS
              (SELECT 1   FROM    saturn.sortest b
              WHERE    A.sortest_tesc_code = b.sortest_tesc_code
                      AND a.sortest_pidm = b.sortest_pidm     
                      and   b.sortest_tesc_code = 'BSV');
     BEGIN
                 UTL_FILE.fclose_all;
                 v_file_handle := UTL_FILE.fopen (v_out_path, v_out_file, 'a');
                UTL_FILE.put_line (v_file_handle,
                      CHR (10) || TO_CHAR (SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
               UTL_FILE.put_line (v_file_handle, 'sortest_best_sct_scorest');
               --check for an open cursor before opening
               IF get_the_max_scores_S01_cur%ISOPEN
                   THEN
                    CLOSE get_the_max_scores_S01_cur;
               END IF;
            OPEN get_the_max_scores_S01_cur;
             LOOP
                   FETCH get_the_max_scores_S01_cur
                   INTO v_pidm, v_tscore, v_testcode,
                           v_test_date, v_equiv_ind;
                   EXIT WHEN get_the_max_scores_S01_cur%NOTFOUND;
               IF  get_the_max_scores_S01_cur%FOUND 
                THEN
                   INSERT INTO saturn.sortest
                   (sortest_pidm,sortest_tesc_code,sortest_test_date,sortest_test_score,
                    sortest_activity_date,sortest_equiv_ind,sortest_user_id,sortest_data_origin)
                    VALUES
                    v_pidm,
                   'BSV',
                    v_test_date,
                     v_tscore,
                     sysdate, 
                    v_equiv_ind,
                    p_user,
                    'best_test_scores process'
               END IF;    
               END LOOP;
               COMMIT;
               ---Initialize variables
                v_pidm := NULL;
                v_test_date := NULL; 
                v_tscore  := NULL; 
                v_equiv_ind :=  NULL;
                v_testcode  :=  NULL;
             CLOSE get_the_max_scores_S01_cur;
----then another do the same for S02...S03

Thank you, here is the code, I change the name of the tables, but it is the same concept.what I need is to extract the max score for each code (s01,s02,s03,s04)
then insert a record with a different code in the same table
BSM     Best Math SAT (S01)                              
BSW     Best writing SAT (S04)     
BSC     Best READING SAT (S03)     
BSE     Best READING SAT (S02)     
I need to be able to check if the BS codes are already in the table (BSM...BSC..) IF they are not do an insert and if they are do an update get the maximun score
again (the students can submit more than one score form the same code and any date) and if the maximun is different(greater) of what is already in the database (with the BSM...BSC.. codes) do an update, IF NOT if is the same or less don't update...
I need the PERSON table because I need to use the ID as a parameter they (user) can run the process for one ID or all the records in the table TEST
Thank you, I hope is clear
create table TEST
TEST_PIDM                  NUMBER(8)            NOT NULL,
TEST_TESC_CODE        VARCHAR2(4 CHAR)     NOT NULL,
TEST_TEST_DATE        DATE                 NOT NULL,
TEST_TEST_SCORE       VARCHAR2(5 CHAR)     NOT NULL,
TEST_ACTIVITY_DATE    DATE                 NOT NULL,
TEST_EQUIV_IND        VARCHAR2(1 CHAR)     NOT NULL
INSERT INTO TEST
( TEST_PIDM, TEST_TESC_CODE,TEST_TEST_DATE, TEST_TEST_SCORE, TEST_ACTIVITY_DATE,TEST_EQUIV_IND)
SELECT
128019,'EB' ,TO_DATE( '01-JUN-2004', 'DD-MON-YYYY'),'710',SYSDATE,'N'
FROM DUAL; 
INSERT INTO TEST
( TEST_PIDM, TEST_TESC_CODE,TEST_TEST_DATE, TEST_TEST_SCORE, TEST_ACTIVITY_DATE,TEST_EQUIV_IND)
SELECT
128019,'M2' ,TO_DATE( '01-JUN-2005', 'DD-MON-YYYY'),'710',SYSDATE,'N'
FROM DUAL; 
INSERT INTO TEST
( TEST_PIDM, TEST_TESC_CODE,TEST_TEST_DATE, TEST_TEST_SCORE, TEST_ACTIVITY_DATE,TEST_EQUIV_IND)
SELECT
128019,'S01' ,TO_DATE( '01-JUN-2005', 'DD-MON-YYYY'),'750',SYSDATE,'N'
FROM DUAL; 
INSERT INTO TEST
( TEST_PIDM, TEST_TESC_CODE,TEST_TEST_DATE, TEST_TEST_SCORE, TEST_ACTIVITY_DATE,TEST_EQUIV_IND)
SELECT
128019,'S01' ,TO_DATE( '01-JUN-2005', 'DD-MON-YYYY'),'720',SYSDATE,'N'
FROM DUAL; 
INSERT INTO TEST
( TEST_PIDM, TEST_TESC_CODE,TEST_TEST_DATE, TEST_TEST_SCORE, TEST_ACTIVITY_DATE,TEST_EQUIV_IND)
SELECT
128019,'S02' ,TO_DATE( '01-JUN-2005', 'DD-MON-YYYY'),'740',SYSDATE,'N'
FROM DUAL; 
INSERT INTO TEST
( TEST_PIDM, TEST_TESC_CODE,TEST_TEST_DATE, TEST_TEST_SCORE, TEST_ACTIVITY_DATE,TEST_EQUIV_IND)
SELECT
128019,'S02' ,TO_DATE( '05-JUL-2005', 'DD-MON-YYYY'),'730',SYSDATE,'N'
FROM DUAL ;
INSERT INTO TEST
( TEST_PIDM, TEST_TESC_CODE,TEST_TEST_DATE, TEST_TEST_SCORE, TEST_ACTIVITY_DATE,TEST_EQUIV_IND)
SELECT
128019,'S03' ,TO_DATE( '01-JUN-2005', 'DD-MON-YYYY'),'780',SYSDATE,'N'
FROM DUAL; 
INSERT INTO TEST
( TEST_PIDM, TEST_TESC_CODE,TEST_TEST_DATE, TEST_TEST_SCORE, TEST_ACTIVITY_DATE,TEST_EQUIV_IND)
SELECT
128019,'S03' ,TO_DATE( '05-JUL-2005', 'DD-MON-YYYY'),'740',SYSDATE,'N'
FROM DUAL; 
INSERT INTO TEST
( TEST_PIDM, TEST_TESC_CODE,TEST_TEST_DATE, TEST_TEST_SCORE, TEST_ACTIVITY_DATE,TEST_EQUIV_IND)
SELECT
128019,'S04' ,TO_DATE( '01-JUN-2005', 'DD-MON-YYYY'),'770',SYSDATE,'N'
FROM DUAL; 
INSERT INTO TEST
( TEST_PIDM, TEST_TESC_CODE,TEST_TEST_DATE, TEST_TEST_SCORE, TEST_ACTIVITY_DATE,TEST_EQUIV_IND)
SELECT
128019,'S04' ,TO_DATE( '05-JUL-2005', 'DD-MON-YYYY'),'740',SYSDATE,'N'
FROM DUAL; 
CREATE TABLE PERSON
  PERSON_PIDM                NUMBER(8)         NOT NULL,
  PERSON_ID                  VARCHAR2(9 CHAR)  NOT NULL
INSERT INTO  PERSON
( PERSON_PIDM ,   PERSON_ID)
SELECT
128019,'003334556'
FROM DUAL ;
CREATE TABLE VALTSC
VALTSC_CODE             VARCHAR2(4 CHAR)     NOT NULL,
  VALTSC_DESC             VARCHAR2(30 CHAR)
INSERT INTO  VALTSC
VALTSC_CODE,
  VALTSC_DESC 
SELECT
'S01' ,
'XXS01'
FROM DUAL; 
  INSERT INTO  VALTSC
VALTSC_CODE,
  VALTSC_DESC 
SELECT
'S02' ,
'XXS02'
FROM DUAL 
  INSERT INTO  VALTSC
VALTSC_CODE,
  VALTSC_DESC 
SELECT
'S03' ,
'XXS03'
FROM DUAL; 
INSERT INTO  VALTSC
VALTSC_CODE,
  VALTSC_DESC 
SELECT
'S04' ,
'XXS04'
FROM DUAL; 

Similar Messages

  • My iPod won't turn on even when I plug it into my charger. I don't want to spend too much fixing it but I need to use it. Please help!!

    My iPod won't turn on even when I plug it into my charger. I don't want to spend too much fixing it but I need to use it. Please help!!

    Try:                                               
    - iOS: Not responding or does not turn on           
    - Also try DFU mode after try recovery mode
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings
    - If not successful and you can't fully turn the iOS device fully off, let the battery fully drain. After charging for an least an hour try the above again.
    - Try another cable              
    - Try on another computer                                                       
    - If still not successful that usually indicates a hardware problem and an appointment at the Genius Bar of an Apple store is in order.
    Apple Retail Store - Genius Bar                                     

  • Is there any way that a normal SMS message (i.e. A green message) can be sent through to an iPad? I have linked my iPad to my phone but I don't want certain messages getting through. If I turn my imessenger off, does this mean these won't go to my ipad?

    Is there any way that a normal SMS message (i.e. A green message) can be sent through to an iPad? I have linked my iPad to my phone but I don't want certain messages getting through. If I turn my imessenger off, does this mean these won't go to my ipad?

    SMS is a voice cell service and since the iPad does not have voice cell circuitry, it does not natively support SMS or MMS. There are third-party apps in the iTunes Store that purport to send SMS, but I have no personal experience with any of them.
    If I turn my imessenger off, does this mean these won't go to my ipad?
    If you disable Messages in the Restrictions on the iPad, then it will not be able to send nor receive messages. Or you can change the email address used for Messages on either the iPad or the iPhone. The iPad will then only receive messages sent via that address.
    For more information, see:
    http://support.apple.com/kb/HT3529
    Regards.

  • I want to print from my iPad in my truck. Is there an easy way of doing this?

    I want to print from my iPad from inside my truck. Is there an easy way to do this?

    The bluetooth is generally meant for keyboards and speakers, no idea if it'd work with a printer.
    I suppose you could shop for printers and look to see if one specifically mentions compantibility with iPads.
    The iPad was created to be a consumption device. Used to consume data, watch movies, read books, listen to music. functionality like what you're wanting is beyond how the device was originally conceived, so it requires tweaking and fixing.
    There are other devices out there that have more functionality, including some that might hardwire to a printer. The easy part would be power for the printer. A $25 inverter will give you that in your vehicle.

  • HT1473 I have a whole bunch of CDs that I would like to import into iTunes. However, I'd like for them to be stored "in the Cloud" as opposed to on my PC, which would simply take up too much space. How would I go about doing this? Thanks so much

    I have a whole bunch of CDs that I would like to import into iTunes. If I do that, would the songs still reside on my PC (which would take up too much space), or is there a way to get them "into the Cloud"? Thanks so much

    Sign up to iTunes Match, though I'd consider investing in more storage. If space is a problem now then you're probably not backing up your existing media and content, which you should most certainly do.
    tt2

  • My power button is pushed in so I have to wait till it goes to sleep and I can't turn it on with out pressing on the home button. I might need it fixed but I really don't want to have too much on my parents but I was wondering if I could do anything else?

    My power button doesn't work and I don't know what I can do without havin my parents spend a lot of money for the power button but I want to. No if their is any other way for me to fix it without damaging it and doing it carefully and I have an iPod touch 4th generation but I really want it to work again without having my iPod wait to go to sleep and its the white one and my brother says the white one isn't that good so ya... But I just want to know if theirs any other solution to this problem cause I'm getting really annoyed by it. Please help me! Thank you! :)

    - Make an appointment at the Genius Bar of an Apple store and hear what they hae to say. It is free.
    Apple Retail Store - Genius Bar                          
    you can turn on Assistive Touch it adds the Power and other buttons to the iPods screen. Settings>General>Accessibility>Assistive Touch

  • I am an exchange student for the year and I would like to by an iphone that i can use in France also, so I need an unlocked one but i don't want to pay to much for it... What should I do?

    I am an exchange student for the year and I would like to by an iphone that i can use in France also, so I need an unlocked one but i don't want to pay to much for it... What should I do?

    What do you mean what should you do?  Just because you don't want to pay too much for a phone, doesn't make the price any cheaper.  If you can't afford the price of an unlocked phone, then you don't, or can't, buy one.

  • I have made a book of my I Photo pictures. In certain layouts there is a textframe. How can I avoid the frame becoming visible in the print if I don't want to write anything? Should I just leave it or should I delete the text "Write your text here" ?

    I have made a book of my iPhoto pictures. In certain layouts there is a text frame. How can I avoid the frame becoming visible in the print if I don't want to write anything?  Should I just leave it untouched or should I delete the instructing text "Write your text here"?

    Most pages have layouts for pictures only or pictures with text boxes. Either select the same layout for that page but the one without the text box or put a space in the text box.
    Putting a space in the text box will avoid getting the warning when ordering that there's an unfilled text box in the book. The box will not be visible in the final product.  You can and should check the book before ordering by previewing it as described in this Apple document: iPhoto '11: Preview a book, card, or calendar before you order or print it
    Happy Holidays

  • I am considering buying a new MAC laptop to run LOGIC for composition and band live/recording, but which one is best as I do not want to spend too much money? Does it have a line in and how do you monitor sound? Will I need adaptors and a interface?

    Can anybody help?
    I am considering buying a new MAC laptop to run LOGIC for composition and band live/recording, but which one is best as I do not want to spend too much money?
    Does it have a line in and how do you monitor sound?
    Will I need adaptors and an interface?
    Also, I am guessing as Logic only runs on MAC surely then they would not the best spec to recommend to run it?
    I see all the upgrades as additional memory or a faster process?
    Is a retina screen necessary, and why flash based storage against a 1TB hard drive, and a i5 instead of an i7
    The main reason for this purchase is to play live and use backing tracks and record found sounds and make creative songs.
    I hope you can provide some valuable feedback, as I am a longtime MAC user and see upgrades and changes happen regularly but the most important thing is the songs not the equipment.
    I have £500 already and willing to add another 500 to 700 pounds, then software extra.

    Can anybody help?
    I am considering buying a new MAC laptop to run LOGIC for composition and band live/recording, but which one is best as I do not want to spend too much money?
    Does it have a line in and how do you monitor sound?
    Will I need adaptors and an interface?
    Also, I am guessing as Logic only runs on MAC surely then they would not the best spec to recommend to run it?
    I see all the upgrades as additional memory or a faster process?
    Is a retina screen necessary, and why flash based storage against a 1TB hard drive, and a i5 instead of an i7
    The main reason for this purchase is to play live and use backing tracks and record found sounds and make creative songs.
    I hope you can provide some valuable feedback, as I am a longtime MAC user and see upgrades and changes happen regularly but the most important thing is the songs not the equipment.
    I have £500 already and willing to add another 500 to 700 pounds, then software extra.

  • HT5557 I bought an ibook but I can't view it without ibooks - I don't want to write a book-I want to read the one that I downloaded

    I bought an ibook but I can't view it without ibooks-I don't want to write a book - I just want to read the one I purchased- how can I do that???

    Ibooks is the program with which you read ibooks.
    Not sure what the issue is.
    Please explain.

  • I allocated too much space on the Windows side when using bootcamp and want to take some space back for the Mac side is there any easy way to do this?

    I allocated too much space on the Windows side when using bootcamp and want to take some space back for the Mac side is there any easy way to do this?

    Purchase and use Paragon Camp Tune

  • Too much code in my answers report!

    Hi experts!
    I'm trying to do a report but there is too much code in my columns. So I have (Removed Column) in the condicionals. Anyway that's an error! Is there any place too change the maximum length of the code I can write?
    Thanks for all!

    Stateless session beans are usually faster, because each client's session is not stateful (therefore has to be handled by the container)
    Have you done some performance measurements on your application?
    Also, how are your session beans communicating with your entity beans?? Are you employing use of Local interfaces to communicate between session<-->entity? Do you have Value Objects that are being passed from session<-->entity? Using Value Objects between s<>e saves a lot of expensive remote calls (especially if you have to get/set a lot of fields)
    Each of these seemingly little decisions can impact your performance greatly.
    HTH,
    -cedrick

  • My husband and I share one computer.  We want to be able to share the same music on our iPhones, but we don't want to share the same contacts and applications.  How can I set this up so we still share music, but everything else is separate on our iPhones?

    My husband and I share one computer.  We want to be able to share the same music on our iPhones, but we don't want to share the same contacts and applications.  How can I set this up so we still share music, but everything else is separate on our iPhones?

    Welcome to the Apple Community.
    iTunes and iCloud are different accounts. You can both use the same ID for the store login and share your music etc., and use different ID's to log in to iCloud, thereby keeping your calendars etc separate.

  • Using iMessage 8.0 with Mavericks to send sms message to my friend who has an iPhone.  Only allows me to log in under AIM, YAHOO, GOOGLE, or BONJOUR.  I don't want to do any of that.  Just my phone number.  Is this possible?

    Using iMessage 8.0 with Mavericks to send sms message to my friend who has an iPhone.  Only allows me to log in under AIM, YAHOO, GOOGLE, or BONJOUR.  I don't want to do any of that.  Just my phone number.  Is this possible?

    Hi,
    The first run of Messages will ask you to enter an Apple ID to "register' with iMessages.
    If you do not do this but open the App and look in Preferences > Accounts then you will see the iMessages account and the Bonjour Account which will not be activated.
    Neither of these two account can be deleted. (even if not being used)
    If you then press the + icon to add you will get the choices you posted.
    To iMessage you need to "register" and Apple ID with the iMessages service.
    As Diane then points out you can link this to your iPhone number.
    This "syncs" (Displays on all devices) the various iMessages sent to either iPhone or Apple ID
    You can then chose  on both iPhone or Mac version how or which ID/Number is going to be used to "Start the conversations from"
    I have my Mac version set to start from my Apple ID and the iPhone from it's number.
    At this moment the Mac version cannot send SMS text messages to an iPhone.
    This is apparently coming with iOS 8 and OS 10.10 (Yosemite)
    An AIM account can send SMS Messages but only to a limited number of USA based phone users on these carriers.
    (Basically you add a phone number with country code +1 as a Buddy to your List)
    Mocked up number  (It not really an auto responder although you do get sent back and Error message about it not being valid)
    8:37 pm      Sunday; July 13, 2014
    ​  iMac 2.5Ghz i5 2011 (Mavericks 10.9)
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb (Snow Leopard 10.6.8)
     Mac OS X (10.6.8),
     Couple of iPhones and an iPad

  • I am attempting to listen to iheart radio. Problem is, there is too much buffering going on. How do I correct this issue?

    I am attempting to listen to iheart radio. Problem is, there is too much buffering going on. How do I correct this issue?

    Robert, did you have an iPhone 4 or 4s?
    And did that iPhone 4 buffer just like the iPhone 5?
    And that is my frustration, I am testing these 2 iPhones next to each other, a 4 and a 5, the 4 plays, the 5 buffers!
    Noooo sir, there is nothing wrong with your phone... Am I going crazy or what?
    I wonder if somebody from Apple reads these posts...
    There must be a solution for this but Nobody seems to know what it is and not a word from the Geniuses this time.
    I am getting a 5s today, I wonder if that solves the problem...

Maybe you are looking for

  • My bluetooth earphones won't stay connected to my Apple Watch!

    As you are reading this question, be sure to note the distinction between PAIR and CONNECT. They are not the same thing and in this question I use them according to their separate definitions/functions. I have an Apple Watch and had no trouble pairin

  • Dynamic Column in multi line format URGENT

    Hi All, I am developing a packing slip report in RTF format and each line has more than one serial numbers like item/QTY Serial Number ITM20401 / 10 SRL1001, SRL1002, SRL1003, SRL1004, SRL1005, SRL1006, SRL1007, SRL1008, SRL1009, SRL1010 Some time re

  • How to implement  Constants of JheadStart Applications

    Hello JheadStart Team we want to gather all constant values of JHS application in one xml file without having to hardcode them in different sections of application (model or view) , and accessing values by binding them anywhere required . Can you giv

  • SQL Performance Degrades Severely in WAN

    The Oracle server is located in the central LAN and the client is located in the remote LAN. These two LANs are connected via 10Mbps wide network. Both LANs are of 100M bps inside. If the SQL commands are issued in the same LAN as Oracle server is lo

  • Cisco Prime Collaboration Provisioning?

    What is  Cisco Prime™ Collaboration Provisioning?