Bulk Insert Through Stored Procedure performance issue

Hello,
i am new to oracle. i am writing a stored procedure through which i want to insert 1 billion record in a table. but it takes days to insert it . please tell me how can i improve performance of my stored procedure. because same stored procedure when i convert it into sql server in take 24 - 30 min to insert 1 billion record.
Code of my stored procedure are as follows :
create or replace PROCEDURE bspGenerateHSCode(
mLoc_id IN INT,
HSCodeStart IN VARCHAR2,
HSCodeEnd IN VARCHAR2,
mRqstId IN INT,
total_count IN INT,
Status OUT INT)
AS
ExitFlag INT;
row_count INT;
mBatchStart NUMBER;
mBatchEnd NUMBER;
mStartSqnc NUMBER;
mEndSqnc NUMBER;
mHSCode VARCHAR2(500);
HSStartStr VARCHAR2(500);
BEGIN
SELECT COUNT(*) INTO row_count FROM goap_eal_allocation
               WHERE hs_code_start = HSCodeStart
AND hs_code_end = HSCodeEnd
AND loc_id = mLoc_id
AND processed = 0;
IF row_count > 0 THEN
SELECT CAST ( REVERSE(substr(REVERSE(HSCodeStart), 1, instr(REVERSE(HSCodeStart), ',') -1)) AS NUMBER) INTO mStartSqnc FROM DUAL;
SELECT CAST ( REVERSE(substr(REVERSE(HSCodeEnd), 1, instr(REVERSE(HSCodeEnd), ',') -1)) AS NUMBER) INTO mEndSqnc FROM DUAL;
SELECT CAST( REVERSE(substr( REVERSE(HSCodeStart), instr(REVERSE(HSCodeStart), ','))) AS VARCHAR2(500) ) INTO HSStartStr FROM DUAL;
mBatchStart := mStartSqnc;
DBMS_OUTPUT.PUT_LINE('start batch ' || mBatchStart);
LOOP
mBatchEnd := mBatchStart + 5000;
IF mBatchEnd > mEndSqnc THEN
mBatchEnd := mEndSqnc + 1;
END IF;
DBMS_OUTPUT.PUT_LINE('End batch ' || mBatchEnd);
LOOP
mHSCode := HSStartStr || mBatchStart;
mBatchStart := mBatchStart + 1;
INSERT INTO goap_eal_register(id, hs_code, loc_id, status_id, synced)
SELECT CASE WHEN MAX(id) > 0 THEN (MAX(id) + 1) ELSE 1 END AS id ,
mHSCode, mLoc_id, 6, 1 FROM goap_eal_register;
EXIT WHEN mBatchStart = mBatchEnd;
END LOOP;
COMMIT;
EXIT WHEN mBatchStart = mEndSqnc +1;
END LOOP;
UPDATE goap_eal_allocation SET processed = 1
WHERE hs_code_start = HSCodeStart
AND hs_code_end = HSCodeEnd
AND loc_id = mLoc_id;
COMMIT;
Status := 1;
ELSE
Status := 0;
END IF;
END;
Thanks

Please edit your post and add \ on the line before and the line after the code to preserve formattingsee how this looks?
Also, when you basically just want to RETURN without doing any work then your first test should just RETURN if you don't want to do any work.
Instead of what your code does:IF row_count > 0 THEN
. . . a whole lot of code that is hard to read or understand
COMMIT;
Status := 1;
ELSE
Status := 0;
END IF;
Test the condition to determine when you do NOT want proceed and just return.IF row_count = 0 THEN
Status := 0;
RETURN;
END IF;
-- now NONE of the following code needs to be indented - you won't get here unless you really want to execute it.
. . . break the code into separate steps and add a one line comment before each step that says what that step does.
COMMIT;
Status := 1;

Similar Messages

  • Stored procedure Performance issue in SQLserver 2005

    Hi All,
    i am inserting the data to Database by using of Stored procedure in target DB.
    My source structure and target structures are looking below
    I have the source structure having lot of rows and look like my structure is below:
    <?xml version="1.0" encoding="utf-8" ?>
    <ns0:POCA0013_KANLOG_REQUEST_MT_response xmlns:ns0="urn:com:POCA0013:sample">
    <SCMDB_response>
    -  <row>
          <PROJK>O-USA</PROJK>
          <KOLLO>123</KOLLO>
       </row>
    -  <row>
          <PROJK>O-Denmark</PROJK>
          <KOLLO>256</KOLLO>
       </row>
        n  number of rows
    </SCMDB_KANLOGVIEW_response>
    </ns0:POCA0013_KANLOG_REQUEST_MT_response>
    and after mapping my target structure is coming to like this.
    <?xml version="1.0" encoding="UTF-8" ?>
    <ns0:POCA0013_DB_MT xmlns:ns0="urn:pg-com POCA0013:sample">
    <StatmentName>
       <XI_SP_DATA action="EXECUTE">
         <PROJEK isInput="TRUE" type="CHAR">O-USA</PROJEK>
         <KOLLO isInput="TRUE" type="CHAR" >123</KOLLO>
       </XI_SP_DATA>
    </StatmentName>
    <StatmentName>
       <XI_SP_DATA action="EXECUTE">
         <PROJEK isInput="TRUE" type="CHAR">O-Denmark</PROJEK>
         <KOLLO isInput="TRUE" type="CHAR" />256</KOLLO>
       </XI_SP_DATA>
    </StatmentName>
      N number of times
    </ns0:POCA0013_DB_MT>
    this is working perfectly to insert the records into the database by using stored procedure. each record  it call the stored procedure for insert the records, for example we had 100 records and it call 100 times stored procedure.
    But in case of huge data, for example 10000 records, it call the 10000 times to stored procedure.in that case we had a problem for database side.
    we have  one reason to use the stored procedure here, because once insert the data into table, if successful log table is created with successful status , if not log table is created with error status. for that purpose i am using stored procedure here.
    Our customer wants to call the stored procedure for one time for all records.How i can manage this situation.
    Can you give me your valuble ideas about this problem.
    Thank you very much.,
    Sateesh
    Edited by: sateesh kumar .N on Apr 23, 2010 6:53 AM
    Edited by: sateesh kumar .N on Apr 23, 2010 6:54 AM
    Edited by: sateesh kumar .N on Apr 23, 2010 7:54 AM

    Hi Sateesh,
    how about a different approach.
    Add 2 more tables to your solution. The first table is used as a staging table, where PI inserts all the data without making any checks, whatsoever. The second table is used as a control table. If the insertion is finished, a log entry is inserted into this second table, containing the information about success or failure or how many rows had been inserted. Put an insert trigger on this table, which in term starts a stored procedure. This stored procedure can read all the data from the staging table and put it into the desired target tables. Additionally you can perform plausiblitiy checks inside this SP.
    Okay I know, this is a complete new solution in comparison to what you did before. But in my experience, this will be much more performant than 10000 calls to one stored procedure who only does inserts as you described.
    Regards
    Sven

  • Can someone help me diagnose a strange stored procedure performance issue please?

    I have a stored procedure (posted below) that returns message recommendations based upon the Yammer Networks you have selected. If I choose one network this query takes less than one second. If I choose another this query takes 9 - 12 seconds.
    /****** Object: StoredProcedure [dbo].[MessageView_GetOutOfContextRecommendations_LargeSet] Script Date: 2/18/2015 3:10:35 PM ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE PROCEDURE [dbo].[MessageView_GetOutOfContextRecommendations_LargeSet]
    -- Parameters
    @UserID int,
    @SourceMessageID int = 0
    AS
    BEGIN
    -- variable for @HomeNeworkUserID
    Declare @HomeNeworkUserID int
    -- Set the HomeNetworkID
    Set @HomeNeworkUserID = (Select HomeNetworkUserID From NetworkUser Where UserID = @UserID)
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON
    -- Begin Select Statement
    Select Top 40 [CreatedDate],[FileDownloadUrl],[HasLinkOrAttachment],[ImagePreviewUrl],[LikesCount],[LinkFileName],[LinkType],[MessageID],[MessageSource],[MessageText],[MessageWebUrl],[NetworkID],[NetworkName],[PosterEmailAddress],[PosterFirstName],[PosterImageUrl],[PosterName],[PosterUserName],[PosterWebUrl],[RepliesCount],[Score],[SmallIconUrl],[Subjects],[SubjectsCount],[UserID]
    -- From View
    From [MessageView]
    -- Do Not Return Any Messages That Have Been Recommended To This User Already
    Where [MessageID] Not In (Select MessageID From MessageRecommendationHistory Where UserID = @UserID)
    -- Do Not Return Any Messages Created By This User
    And [UserID] != @UserID
    -- Do Not Return The MessageID
    And [MessageID] != @SourceMessageID
    -- Only return messages for the Networks the user has selected
    And [NetworkID] In (Select NetworkID From NetworkUser Where [HomeNetworkUserID] = @HomeNeworkUserID And [AllowRecommendations] = 1)
    -- Order By [MessageScore] and [MessageCreatedDate] in reverse order
    Order By [Score] desc, [CreatedDate] desc
    ENDThe Actual Execution Plan Shows up the same; there are more messages on the Network that is slow, 2800 versus 1,500 but the difference is ten times longer on the slow network.Is the fact I am doing a Top 40 what makes it slow? My first guess was to take the Order By Off and that didn't seem to make any difference.The execution plan is below, it takes 62% of the query to look up theIX_Message.Score which is the clustered index, so I thought this would be fast. Also the Clustered Index Seek for the User.UserID take 26%which seems high for what it is doing.
    I have indexes on every field that is queried on so I am kind of at a loss as to where to go next.
    It just seems strange because it is the same view being queried in both cases.
    I tried to run the SQL Server Tuning Wizard but it doesn't run on Azure SQL, and my problem doesn't occur on the data in my local database.
    Thanks for any guidance, I know a lot of the slowness is due to the lower tier Azure SQL we are using, many of the performance issues weren't noticed when were on the full SQL Server, but the other networks work extremely fast so it has to be something to
    with having more rows.
    In case you need the SQL for the View that I am querying it is:
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE VIEW [dbo].[MessageView]
    AS
    SELECT M.UserID, M.MessageID, M.NetworkID, N.Name AS NetworkName, M.Subjects, M.SubjectsCount, M.RepliesCount, M.LikesCount, M.CreatedDate, M.MessageText, M.HasLinkOrAttachment, M.Score, M.WebUrl AS MessageWebUrl, U.UserName AS PosterUserName,
    U.Name AS PosterName, U.FirstName AS PosterFirstName, U.ImageUrl AS PosterImageUrl, U.EmailAddress AS PosterEmailAddress, U.WebUrl AS PosterWebUrl, M.MessageSource, M.ImagePreviewUrl, M.LinkFileName, M.FileDownloadUrl, M.LinkType, M.SmallIconUrl
    FROM dbo.Message AS M INNER JOIN
    dbo.Network AS N ON M.NetworkID = N.NetworkID INNER JOIN
    dbo.[User] AS U ON M.UserID = U.UserID
    GO
    The Network Table has an Index on Network ID, but it non clustered but I don't think that is the culprit.
    Corby

    I marked your response as answer because you gave me information I didn't have about the sort. I ended up rewriting the query to be a join instead of the In's and it improved dramatically, about one second on a very minimal Azure SQL database, and before
    it was 12 seconds on one network. We didn't notice the problem at all before we moved to Azure SQL, it was about one - three seconds at most.
    Here is the updated way that was much more efficient:
    CREATE PROCEDURE [dbo].[Procedure Name]
    -- Parameters
    @UserID int,
    @SourceMessageID int = 0
    AS
    BEGIN
    -- variable for @HomeNeworkUserID
    Declare @HomeNeworkUserID int
    -- Set the HomeNetworkID
    Set @HomeNeworkUserID = (Select HomeNetworkUserID From NetworkUser Where UserID = @UserID)
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON
    ;With cteMessages As
    -- Begin Select Statement
    Select (Fields List)
    -- Join to Network Table
    From MessageView mv Inner Join NetworkUser nu on MV.NetworkID = nu.NetworKID -- Only Return Networks This User Has Selected
    Where nu.HomeNetworkUserID = @HomeNeworkUserID And AllowRecommendations = 1
    -- Do Not Return Any Messages Created By This User
    And mv.[UserID] != @UserID
    -- Do Not Return The MessageID
    And mv.[MessageID] != @SourceMessageID
    ), cteHistoryForThisUser As
    Select MessageID From MessageRecommendationHistory Where UserID = @UserID
    -- Begin Select Statement
    Select Top 40 (Fields List)
    -- Join to Network Table
    From cteMessages m Left Outer Join cteHistoryForThisUser h on m.MessageID = h.MessageID
    -- Do Not Return Any Items Where User Has Already been shown this Message
    Where h.MessageID Is Null
    -- An Order By Is Needed To Get The Best Content First
    Order By Score Desc
    END
    GO
    The Left Outer Join to test for null was the biggest improvement, but it also helped to join to the NetworkUser table instead of do the In sub query.

  • Bulk insert using stored procedure or trigger

    Hi ,
    I have to insert around 40,000 rows in a table querying other database using database link.
    Please advice whether I do using stored procedure or trigger.
    Thanks.

    Here is a basic benchmark that illustrates the difference between maximising SQL, or doing it in PL/SQL instead.
    Care needs to be taken with such a benchmark in order for physical I/O not to negatively impact a test, and then have no impact in the second test as that data read from disk now sits in the cache.
    So I ran it a couple of times in order to "warm up" the cache. I also put the maximise-SQL test first in order to show that it is still faster, despite any physical I/O it may do (which will likely be faster logical I/O with the second test).
    Run on Oracle XE 10.2.0.1.
    SQL> drop table my_objects_copy purge;
    Table dropped.
    SQL> create table my_objects_copy as select * from all_objects;
    Table created.
    SQL>
    SQL> set timing on
    SQL> begin
    2 delete from my_objects_copy;
    3
    4 insert into my_objects_copy
    5 select * from all_objects;
    6
    7 commit;
    8 end;
    9 /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:01.11
    SQL> set timing off
    SQL>
    SQL> drop table my_objects_copy purge;
    Table dropped.
    SQL> create table my_objects_copy as select * from all_objects;
    Table created.
    SQL>
    SQL> set timing on
    SQL> declare
    2 cursor c is select * from all_objects;
    3 objRow ALL_OBJECTS%ROWTYPE;
    4 begin
    5 delete from my_objects_copy;
    6
    7 open c;
    8 loop
    9 fetch c into objRow;
    10 exit when c%NOTFOUND;
    11
    12 insert into my_objects_copy
    13 values objRow;
    14
    15 end loop;
    16 commit;
    17 end;
    18 /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:03.21
    SQL>
    The cursor-fetch-loop is almost 3 times slower. The more rows there are to process, the slower the cursor-fetch-loop will become, as it will create more and more context switching and copying data between the SQL and PL engines and back.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Stored Procedure Performance Issue in Sharepoint Report

    We have a report stored procedure that runs in about 1 minute in production; however, when executed from the Sharepoint it populates, it runs for over 20 minutes, with exactly the same parameters. We've done everything to avoid parameter sniffing problems:
    used WITH RECOMPILE on the procedure declaration; added OPTION OPTIMIZE FOR UNKNOWN on the parameters within queries; even created local variables and assigned the parameter values to them and used them throughout the procedure. None of these has had any effect.
    I know that the 1-base minute run time is a big red flag, and we're working on pre-aggregating this data into our BI platform, but that's months down the liine and this is needed for month-end close every month.
    Other relevant information:
    Sharepoint 2013 on SQL Server 2012
    Data Source is a SQL Server 2008 R2 database
    Report definition created in Visual Studio 2008

    I'm trying to figure out why it's taking so long.  When I query on ExecutionLog3 I see the following (converted to seconds):
    Total Seconds
    Retrieval Seconds
    Processing Seconds
    Rendering Seconds
    ByteCount
    RowCount
    653.966
    653.933
    0.018
    0.015
    15037
    1
    Yet running in SSMS, it completes (consistently) in 62 seconds.

  • Bulk Insertion through a procedure

    There are 6 Million row in core_business.cb_insured_person_detail@pcba which i want to insert into same table on other node. I can not use simple simple Insert into ....... Select * from ...... because of some exception. This procedure is working but consuming lot of time, i want to fasten, this process, for which i need help........... I kept Exception clause simple, because there are very few records, which are creating problem.
    create or replace
    PROCEDURE            ip_detail_insertion
    AS
       rec_cnt       NUMBER (10);
       rec_cnt_tmp   NUMBER (6);
    BEGIN
       FOR sel_rec IN (SELECT *
                         FROM core_business.cb_insured_person_detail@pcba)
       LOOP
          BEGIN
             INSERT INTO core_business.cb_insured_person_detail
                  VALUES (sel_rec.ip_region_fo_code, sel_rec.ip_check_digit,
                          sel_rec.ip_serial_no, sel_rec.emp_area_code,
                          sel_rec.emp_reg_serial_no, sel_rec.emp_sub_area_code,
                          sel_rec.emp_sub_serial_no, sel_rec.serial_no,
                          sel_rec.entry_date, sel_rec.exit_date,
                          sel_rec.exit_info_date, sel_rec.current_wages,
                          sel_rec.ibco_no, sel_rec.pmt_slip_no,
                          sel_rec.scheme_code, sel_rec.remarks,
                          sel_rec.nature_of_occupation, sel_rec.status,
                          sel_rec.created_by, sel_rec.created_date,
                          sel_rec.modified_by, sel_rec.modified_date,
                          sel_rec.eobi_no, sel_rec.old_eobi_no,
                          sel_rec.orphanage_date, sel_rec.pkey);
             COMMIT;
             rec_cnt := rec_cnt + 1;
             rec_cnt_tmp := rec_cnt_tmp + 1;
             IF rec_cnt_tmp > 999999
             THEN
                DBMS_OUTPUT.put_line ('Insertion = ' || rec_cnt);
                rec_cnt_tmp := 0;
             END IF;
          EXCEPTION
             WHEN OTHERS
             THEN
                NULL;
          END;
       END LOOP;
    END;

    Saubhik wrote:
    You will get some beating from the Gurus ;) Because
    1. WHEN OTHERS THEN NULL
    http://tkyte.blogspot.com/2008/06/when-others-then-null-redux.html
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:4018285967344#671326800346790791
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:677074900346092274
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1509245700346768268#tom1535781400346575552
    2. COMMIT in a loop
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:7661190956484
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:4951966319022
    3. Using Pl/SQL for what can be done by SQL
    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:760210800346068768
    By the way for exception handling you may want to look at DBMS_ERRLOG.
    Can this be done without loop?
    If you correct all these, then your process will be faster automatically!.
    Edited by: Saubhik on Nov 3, 2010 12:39 AMAmen.
    What errors are you getting?

  • How to retrive data through stored procedure in mysql from remote machine?

    Hello everybody,
    I am having problem in accessing data of mysql through stored procedure. It works fine if I use "jdbc:mysql://localhost:3306/[database name]" instead of "jdbc:mysql://[IP address]:3306/[database name]". The connection is fine for both, but when stored procedure is called the system stops at "stmt.execute();" line in java file while debuging. In case of localhost there is no any problem. The code for connecting procedure is:
    stmt = dbConn.prepareCall("{? = call testing()}"); stmt.registerOutParameter(1, Types.VARCHAR); stmt.execute();
    I have to connect java application running in Windows to the mysql database running in remote machine(RHEL 5).
    I am using "mysql-connector-java-5.1.5-bin.jar", jdk 1.5.0 and remote database Mysql version : 5.0.22.
    There is no exception and application hangs at stmt.execute();
    Can anybody help me with this problem?
    Thank you.

    I got it. its about connection...

  • Sending Long Raw Data to Oracle database through Stored  Procedure

    Hi,
    I am trying to push data to Oracle 9i database through Stored Procedure via thin driver. It is going smoothly upto 29411 bytes. But it is not accepting for 53843 bytes and giving following error :
    java.sql.SQLException: Data size bigger than max size for this type: 53843
    Is it thin driver limitation? Can I solve it by using OCI driver? Or is there any other approach?
    I tried creating connection pool in weblogic 7.0 through OCI driver. But I am not able to configure it. Is there any special way of configuration.
    Quick response will be greatly appreciated.
    Thanks
    Sanjiv

    It happens to me. But I am using CMP of Weblogic 7. If you write your own jdbc code, the following link may be helpful.
    http://otn.oracle.com/sample_code/tech/java/codesnippet/xmldb/HowToLoadLargeXML.html

  • Insert Into Vs Insert through a Procedure

    Hi All,
    I want to make a comparison between insertion into a table through normal insert into staement and through a procedure.
    I create a table call test_table with 6 columns and a procedure to insert in that table.
    I opened a session that make normal insert for 32 times and another session that uses the procedure to insert for 39 times. My experience says that insertion through a procedure is faster than normal insert into statement. but when i make trace for both sessions here is the results:
    Session1(Normal Insert)
    INSERT INTO TEST_TABLE
    VALUES(:"SYS_B_0", :"SYS_B_1", :"SYS_B_2", :"SYS_B_3", :"SYS_B_4", :"SYS_B_5")
    call count cpu elapsed disk query current rows
    Parse 32 0.00 0.00 0 0 0 0
    Execute 32 0.01 0.02 0 32 129 32
    Fetch 0 0.00 0.00 0 0 0 0
    total 64 0.01 0.03 0 32 129 32
    Misses in library cache during parse: 1
    Optimizer mode: CHOOSE
    Parsing user id: 125 (CALLCNTR44)
    Rows Execution Plan
    0 INSERT STATEMENT MODE: CHOOSE
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call count cpu elapsed disk query current rows
    Parse 32 0.00 0.00 0 0 0 0
    Execute 32 0.01 0.02 0 32 129 32
    Fetch 0 0.00 0.00 0 0 0 0
    total 64 0.01 0.03 0 32 129 32
    Misses in library cache during parse: 1
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call count cpu elapsed disk query current rows
    Parse 0 0.00 0.00 0 0 0 0
    Execute 0 0.00 0.00 0 0 0 0
    Fetch 0 0.00 0.00 0 0 0 0
    total 0 0.00 0.00 0 0 0 0
    Misses in library cache during parse: 0
    32 user SQL statements in session.
    0 internal SQL statements in session.
    32 SQL statements in session.
    1 statement EXPLAINed in this session.
    Trace for Session2(Procedure Insert)
    BEGIN sec1.INSERT_INTO_TEXT_TABLE (); END;
    call count cpu elapsed disk query current rows
    Parse 39 0.04 0.00 0 0 0 0
    Execute 39 0.00 0.00 0 0 0 39
    Fetch 0 0.00 0.00 0 0 0 0
    total 78 0.04 0.01 0 0 0 39
    Misses in library cache during parse: 1
    Optimizer mode: CHOOSE
    Parsing user id: 125 (CALLCNTR44)
    INSERT INTO TEST_TABLE
    VALUES('TEST COL1', 'TEST COL2', 'TEST COL3', 'TEST COL4', 'TEST COL5', 'TEST COL6')
    call count cpu elapsed disk query current rows
    Parse 0 0.00 0.00 0 0 0 0
    Execute 39 0.03 0.00 0 0 80 39
    Fetch 0 0.00 0.00 0 0 0 0
    total 39 0.03 0.00 0 0 80 39
    Misses in library cache during parse: 0
    Optimizer mode: CHOOSE
    Parsing user id: 474 (SEC1) (recursive depth: 1)
    Rows Execution Plan
    0 INSERT STATEMENT MODE: CHOOSE
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call count cpu elapsed disk query current rows
    Parse 117 0.04 0.02 0 0 0 0
    Execute 117 0.03 0.03 0 0 0 78
    Fetch 39 0.03 0.00 0 312 0 0
    total 273 0.10 0.06 0 312 0 78
    Misses in library cache during parse: 3
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call count cpu elapsed disk query current rows
    Parse 2 0.00 0.00 0 0 0 0
    Execute 41 0.04 0.01 0 0 80 39
    Fetch 2 0.00 0.00 1 5 0 2
    total 45 0.04 0.02 1 5 80 41
    Misses in library cache during parse: 2
    118 user SQL statements in session.
    2 internal SQL statements in session.
    120 SQL statements in session.
    1 statement EXPLAINed in this session.
    So in session 2 parsing of the procedure it self is still done in each execution but for the statment inside it no and in session1 parsing for the insert is done for every execution. So does this proof my knowledge or it is wrong?
    I see that instead of parsing the insert in session1 there is parsing for the procedure in session2 is that correct?
    Thanks in advance

    Tomy3k_Bakr, you are doing the comparison wrong. Are you running these from sqlplus over and over again? Sqlplus parses every statement you send, this is not the correct way to compare.
    Try this instead.
    YAS@10G>create table t (a number,b number,c number);
    Table created.
    YAS@10G>r
      1  create or replace procedure insert_t(pa number,pb number,pc number) as
      2  begin
      3     insert into t values(pa,pb,pc);
      4* end;
    Procedure created.Run this and see the results.
    exec RUNSTATS_PKG.rs_start;
    begin
    for i in 1..10000 loop
         insert /*+ sql */ into t values(i,i,i);
    end loop;
    end;
    exec RUNSTATS_PKG.rs_middle;
    begin
    for i in 1..10000 loop
         insert_t(i,i,i);
    end loop;
    end;
    exec RUNSTATS_PKG.rs_stop;
    Run1 ran in 124 hsecs
    Run2 ran in 139 hsecs
    run 1 ran in 89.21% of the time
    Name                                  Run1        Run2        Diff
    LATCH.list of block allocation           1           0          -1
    STAT...redo ordering marks              92          91          -1
    STAT...table scans (short tabl           3           2          -1
    LATCH.session idle bit                  27          26          -1
    LATCH.In memory undo latch               0           1           1
    LATCH.file cache latch                   3           2          -1
    LATCH.redo allocation                    8           7          -1
    LATCH.archive process latch              1           0          -1
    LATCH.Consistent RBA                     2           3           1
    LATCH.lgwr LWN SCN                       3           2          -1
    LATCH.mostly latch-free SCN              3           2          -1
    LATCH.KMG MMAN ready and start           1           0          -1
    LATCH.compile environment latc           3           2          -1
    LATCH.session timer                      0           1           1
    LATCH.shared pool                        2           3           1
    STAT...change write time                11          12           1
    STAT...table scan blocks gotte           6           4          -2
    STAT...messages sent                     2           4           2
    STAT...data blocks consistent            3           1          -2
    LATCH.channel operations paren           8           6          -2
    STAT...rollbacks only - consis           3           1          -2
    STAT...cleanout - number of kt          27          31           4
    STAT...index fetch by key                6           2          -4
    STAT...cluster key scans                 6           2          -4
    STAT...active txn count during          27          31           4
    STAT...deferred (CURRENT) bloc           6           2          -4
    STAT...consistent changes               20          24           4
    STAT...consistent gets - exami          39          35          -4
    STAT...session cursor cache hi          11           7          -4
    STAT...CR blocks created                 6           2          -4
    STAT...commit cleanouts succes           6           2          -4
    STAT...commit cleanouts                  6           2          -4
    STAT...workarea memory allocat           5           1          -4
    STAT...calls to kcmgcs                  27          31           4
    STAT...execute count                10,014      10,009          -5
    LATCH.active checkpoint queue            5           0          -5
    STAT...opened cursors cumulati          14           8          -6
    STAT...db block changes             20,324      20,318          -6
    LATCH.redo writing                      14           8          -6
    STAT...parse count (total)              14           8          -6
    STAT...CPU used when call star         131         138           7
    STAT...calls to kcmgas                 101          94          -7
    LATCH.undo global data                  50          43          -7
    STAT...no work - consistent re          15           7          -8
    LATCH.dml lock allocation               12           4          -8
    STAT...DB time                         132         140           8
    STAT...cluster key scan block           12           4          -8
    LATCH.library cache lock                16           8          -8
    STAT...buffer is not pinned co          12           4          -8
    LATCH.messages                          27          17         -10
    STAT...db block gets from cach      10,484      10,473         -11
    STAT...db block gets                10,484      10,473         -11
    STAT...enqueue releases                 24          13         -11
    STAT...enqueue requests                 24          13         -11
    STAT...recursive cpu usage              96         107          11
    STAT...Elapsed Time                    127         140          13
    LATCH.enqueues                          35          22         -13
    STAT...redo entries                 10,181      10,195          14
    STAT...CPU used by this sessio         124         138          14
    LATCH.library cache pin             20,072      20,056         -16
    LATCH.cache buffers lru chain          135         153          18
    STAT...table scan rows gotten           54          36         -18
    STAT...calls to get snapshot s          37          19         -18
    LATCH.library cache                 20,094      20,073         -21
    LATCH.enqueue hash chains               50          26         -24
    STAT...bytes received via SQL*       1,210       1,185         -25
    STAT...consistent gets                  91          63         -28
    STAT...consistent gets from ca          91          63         -28
    STAT...free buffer requested           118         152          34
    STAT...session logical reads        10,575      10,536         -39
    LATCH.row cache objects                153         106         -47
    LATCH.checkpoint queue latch            57           0         -57
    LATCH.SQL memory manager worka          73           6         -67
    LATCH.cache buffer handles              16          84          68
    STAT...recursive calls              10,132      10,053         -79
    LATCH.object queue header oper         334         437         103
    LATCH.cache buffers chains          51,652      51,526        -126
    LATCH.session allocation               258         104        -154
    STAT...free buffer inspected           448         188        -260
    LATCH.simulator lru latch              440         865         425
    LATCH.simulator hash latch             458         892         434
    STAT...hot buffers moved to he       1,222         276        -946
    STAT...undo change vector size     684,064     682,932      -1,132
    STAT...redo size                 2,586,108   2,583,908      -2,200
    Run1 latches total versus runs -- difference and pct
    Run1        Run2        Diff       Pct
    94,017      94,489         472     99.50%For runstats see http://asktom.oracle.com/tkyte/runstats.html.

  • Return a parameter through stored procedures

    Hello Experts
    I want to return parameter through stored procedures so as to ensure that the application has been executed properly.
    My source message format is
    <StatementName5>
    <storedProcedureName action=u201D EXECUTEu201D>
      <table>Summarize_prc</table>
    <empid  [isInput=u201Dtrueu201D] [isOutput=true] type=SQLDatatype>val1</empid>
    </storedProcedureName > 
    </StatementName5>
    Do i need to put some extra parameters for return values from the stored procedures?
    What would be the response message format to return the parameters from stored procedure.
    Thanks
    Sabyasachi

    Hi,
    If you wants to read the return values from stored procedure, the scanario should be designed as Sync.
    The format looks like thsi
    <Message Type Name>
          <STATEMENTNAME_response>
                      <Field1> </Field1>
       </STATEMENTNAME_response>
    </Message Type Name>

  • Problem in Inserting the Value in the column through Stored Procedure

    stored procedure is created and i need
    to insert data into the SALES_TRADEIN, from the parent table (Flatfile_sales),through COMMAND PROMPT.
    I have 2 details TradeIn_1 and TradeIn_2.
    I need to insert details of TradeIn_1 in SALES_TRADEIN
    TABLE if the column of TradeIn_1 is null then i need to insert TradeIn_2 details.
    If the TradeIn_1 is not null then i have insert
    TradeIn_1 details and go to next column.
    This is the Scenario but i wrote the Script
    so anyone please view it and give the solution how to change that insert statement.
    -- =============================================
    -- Stored Procedure for Flatfile_Sales
    -- =============================================
    ---==========Sales_Cursor
    --USE [IconicMarketing]
    --GO
    DECLARE
    @FileType varchar(50),
    @ACDealerID varchar(50),
    @ClientDealerID varchar(50),
    @DMSType varchar(50),
    @DealNumber varchar(50),
    @CustomerNumber varchar(50),
    @CustomerName varchar(50),
    @CustomerFirstName varchar(50),
    @CustomerLastName varchar(50),
    @CustomerAddress varchar(50),
    @CustomerCity varchar(50),
    @CustomerState varchar(50),
    @CustomerZip varchar(50),
    @CustomerCounty varchar(50),
    @CustomerHomePhone varchar(50),
    @CustomerWorkPhone varchar(50),
    @CustomerCellPhone varchar(50),
    @CustomerPagerPhone varchar(50),
    @CustomerEmail varchar(50),
    @CustomerBirthDate varchar(50),
    @MailBlock varchar(50),
    @CoBuyerName varchar(50),
    @CoBuyerFirstName varchar(50),
    @CoBuyerLastName varchar(50),
    @CoBuyerAddress varchar(50),
    @CoBuyerCity varchar(50),
    @CoBuyerState varchar(50),
    @CoBuyerZip varchar(50),
    @CoBuyerCounty varchar(50),
    @CoBuyerHomePhone varchar(50),
    @CoBuyerWorkPhone varchar(50),
    @CoBuyerBirthDate varchar(50),
    @Salesman_1_Number varchar(50),
    @Salesman_1_Name varchar(50),
    @Salesman_2_Number varchar(50),
    @Salesman_2_Name varchar(50),
    @ClosingManagerName varchar(50),
    @ClosingManagerNumber varchar(50),
    @F_AND_I_ManagerNumber varchar(50),
    @F_AND_I_ManagerName varchar(50),
    @SalesManagerNumber varchar(50),
    @SalesManagerName varchar(50),
    @EntryDate varchar(50),
    @DealBookDate varchar(50),
    @VehicleYear varchar(50),
    @VehicleMake varchar(50),
    @VehicleModel varchar(50),
    @VehicleStockNumber varchar(50),
    @VehicleVIN varchar(50),
    @VehicleExteriorColor varchar(50),
    @VehicleInteriorColor varchar(50),
    @VehicleMileage varchar(50),
    @VehicleType varchar(50),
    @InServiceDate varchar(50),
    @HoldBackAmount varchar(50),
    @DealType varchar(50),
    @SaleType varchar(50),
    @BankCode varchar(50),
    @BankName varchar(50),
    @SalesmanCommission varchar(50),
    @GrossProfitSale varchar(50),
    @FinanceReserve varchar(50),
    @CreditLifePremium varchar(50),
    @CreditLifeCommision varchar(50),
    @TotalInsuranceReserve varchar(50),
    @BalloonAmount varchar(50),
    @CashPrice varchar(50),
    @AmountFinanced varchar(50),
    @TotalOfPayments varchar(50),
    @MSRP varchar(50),
    @DownPayment varchar(50),
    @SecurityDesposit varchar(50),
    @Rebate varchar(50),
    @Term varchar(50),
    @RetailPayment varchar(50),
    @PaymentType varchar(50),
    @RetailFirstPayDate varchar(50),
    @LeaseFirstPayDate varchar(50),
    @DayToFirstPayment varchar(50),
    @LeaseAnnualMiles varchar(50),
    @MileageRate varchar(50),
    @APRRate varchar(50),
    @ResidualAmount varchar(50),
    @LicenseFee varchar(50),
    @RegistrationFee varchar(50),
    @TotalTax varchar(50),
    @ExtendedWarrantyName varchar(50),
    @ExtendedWarrantyTerm varchar(50),
    @ExtendedWarrantyLimitMiles varchar(50),
    @ExtendedWarrantyDollar varchar(50),
    @ExtendedWarrantyProfit varchar(50),
    @FrontGross varchar(50),
    @BackGross varchar(50),
    @TradeIn_1_VIN varchar(50),
    @TradeIn_2_VIN varchar(50),
    @TradeIn_1_Make varchar(50),
    @TradeIn_2_Make varchar(50),
    @TradeIn_1_Model varchar(50),
    @TradeIn_2_Model varchar(50),
    @TradeIn_1_ExteriorColor varchar(50),
    @TradeIn_2_ExteriorColor varchar(50),
    @TradeIn_1_Year varchar(50),
    @TradeIn_2_Year varchar(50),
    @TradeIn_1_Mileage varchar(50),
    @TradeIn_2_Mileage varchar(50),
    @TradeIn_1_Gross varchar(50),
    @TradeIn_2_Gross varchar(50),
    @TradeIn_1_Payoff varchar(50),
    @TradeIn_2_Payoff varchar(50),
    @TradeIn_1_ACV varchar(50),
    @TradeIn_2_ACV varchar(50),
    @Fee_1_Name varchar(50),
    @Fee_1_Fee varchar(50),
    @Fee_1_Commission varchar(50),
    @Fee_2_Name varchar(50),
    @Fee_2_Fee varchar(50),
    @Fee_2_Commission varchar(50),
    @Fee_3_Name varchar(50),
    @Fee_3_Fee varchar(50),
    @Fee_3_Commission varchar(50),
    @Fee_4_Name varchar(50),
    @Fee_4_Fee varchar(50),
    @Fee_4_Commission varchar(50),
    @Fee_5_Name varchar(50),
    @Fee_5_Fee varchar(50),
    @Fee_5_Commission varchar(50),
    @Fee_6_Name varchar(50),
    @Fee_6_Fee varchar(50),
    @Fee_6_Commission varchar(50),
    @Fee_7_Name varchar(50),
    @Fee_7_Fee varchar(50),
    @Fee_7_Commission varchar(50),
    @Fee_8_Name varchar(50),
    @Fee_8_Fee varchar(50),
    @Fee_8_Commission varchar(50),
    @Fee_9_Name varchar(50),
    @Fee_9_Fee varchar(50),
    @Fee_9_Commission varchar(50),
    @Fee_10_Name varchar(50),
    @Fee_10_Fee varchar(50),
    @Fee_10_Commission varchar(50),
    @ContractDate varchar(50),
    @InsuranceName varchar(50),
    @InsuranceAgentName varchar(50),
    @InsuranceAddress varchar(50),
    @InsuranceCity varchar(50),
    @InsuranceState varchar(50),
    @InsuranceZip varchar(50),
    @InsurancePhone varchar(50),
    @InsurancePolicyNumber varchar(50),
    @InsuranceEffectiveDate varchar(50),
    @InsuranceExpirationDate varchar(50),
    @InsuranceCompensationDeduction varchar(50),
    @TradeIn_1_InteriorColor varchar(50),
    @TradeIn_2_InteriorColor varchar(50),
    @PhoneBlock varchar(50),
    @LicensePlateNumber varchar(50),
    @Cost varchar(50),
    @InvoiceAmount varchar(50),
    @FinanceCharge varchar(50),
    @TotalPickupPayment varchar(50),
    @TotalAccessories varchar(50),
    @TotalDriveOffAmount varchar(50),
    @EmailBlock varchar(50),
    @ModelDescriptionOfCarSold varchar(50),
    @VehicleClassification varchar(50),
    @ModelNumberOfCarSold varchar(50),
    @GAPPremium varchar(50),
    @LastInstallmentDate varchar(50),
    @CashDeposit varchar(50),
    @AHPremium varchar(50),
    @LeaseRate varchar(50),
    @DealerSelect varchar(50),
    @LeasePayment varchar(50),
    @LeaseNetCapCost varchar(50),
    @LeaseTotalCapReduction varchar(50),
    @DealStatus varchar(50),
    @CustomerSuffix varchar(50),
    @CustomerSalutation varchar(50),
    @CustomerAddress2 varchar(50),
    @CustomerMiddleName varchar(50),
    @GlobalOptOut varchar(50),
    @LeaseTerm varchar(50),
    @ExtendedWarrantyFlag varchar(50),
    @Salesman_3_Number varchar(50),
    @Salesman_3_Name varchar(50),
    @Salesman_4_Number varchar(50),
    @Salesman_4_Name varchar(50),
    @Salesman_5_Number varchar(50),
    @Salesman_5_Name varchar(50),
    @Salesman_6_Number varchar(50),
    @Salesman_6_Name varchar(50),
    @APRRate2 varchar(50),
    @APRRate3 varchar(50),
    @APRRate4 varchar(50),
    @Term2 varchar(50),
    @SecurityDeposit2 varchar(50),
    @DownPayment2 varchar(50),
    @TotalOfPayments2 varchar(50),
    @BasePayment varchar(50),
    @JournalSaleAmount varchar(50),
    @IndividualBusinessFlag varchar(50),
    @InventoryDate varchar(50),
    @StatusDate varchar(50),
    @ListPrice varchar(50),
    @NetTradeAmount varchar(50),
    @TrimLevel varchar(50),
    @SubTrimLevel varchar(50),
    @BodyDescription varchar(50),
    @BodyDoorCount varchar(50),
    @TransmissionDesc varchar(50),
    @EngineDesc varchar(50),
    @TypeCode varchar(50),
    @SLCT2 varchar(50),
    @DealDateOffset varchar(50),
    @AccountingDate varchar(50),
    @CoBuyerCustNum varchar(50),
    @CoBuyerCell varchar(50),
    @CoBuyerEmail varchar(50),
    @CoBuyerSalutation varchar(50),
    @CoBuyerPhoneBlock varchar(50),
    @CoBuyerMailBlock varchar(50),
    @CoBuyerEmailBlock varchar(50),
    @RealBookDate varchar(50),
    @CoBuyerMiddleName varchar(50),
    @CoBuyerCountry varchar(50),
    @CoBuyerAddress2 varchar(50),
    @CoBuyerOptOut varchar(50),
    @CoBuyerOccupation varchar(50),
    @CoBuyerEmployer varchar(50),
    @Country varchar(50),
    @Occupation varchar(50),
    @Employer varchar(50),
    @Salesman2Commission varchar(50),
    @BankAddress varchar(50),
    @BankCity varchar(50),
    @BankState varchar(50),
    @BankZip varchar(50),
    @LeaseEstimatedMiles varchar(50),
    @AFTReserve varchar(50),
    @CreditLifePrem varchar(50),
    @CreditLifeRes varchar(50),
    @AHRes varchar(50),
    @Language varchar(50),
    @BuyRate varchar(50),
    @DMVAmount varchar(50),
    @Weight varchar(50),
    @StateDMVTotFee varchar(50),
    @ROSNumber varchar(50),
    @Incentives varchar(50),
    @CASS_STD_LINE1 varchar(50),
    @CASS_STD_LINE2 varchar(50),
    @CASS_STD_CITY varchar(50),
    @CASS_STD_STATE varchar(50),
    @CASS_STD_ZIP varchar(50),
    @CASS_STD_ZIP4 varchar(50),
    @CASS_STD_DPBC varchar(50),
    @CASS_STD_CHKDGT varchar(50),
    @CASS_STD_CART varchar(50),
    @CASS_STD_LOT varchar(50),
    @CASS_STD_LOTORD varchar(50),
    @CASS_STD_URB varchar(50),
    @CASS_STD_FIPS varchar(50),
    @CASS_STD_EWS varchar(50),
    @CASS_STD_LACS varchar(50),
    @CASS_STD_ZIPMOV varchar(50),
    @CASS_STD_Z4LOM varchar(50),
    @CASS_STD_NDIAPT varchar(50),
    @CASS_STD_NDIRR varchar(50),
    @CASS_STD_LACSRT varchar(50),
    @CASS_STD_ERROR_CD varchar(50),
    @NCOA_AC_ID varchar(50),
    @NCOA_COA_ADDSRC varchar(50),
    @NCOA_COA_MATCH varchar(50),
    @NCOA_COA_MOVTYP varchar(50),
    @NCOA_COA_DATE varchar(50),
    @NCOA_COA_DELCD varchar(50),
    @NCOA_COA_RTYPE varchar(50),
    @NCOA_COA_RTNCD varchar(50),
    @NCOA_COA_LINE1 varchar(50),
    @NCOA_COA_LINE2 varchar(50),
    @NCOA_COA_CITY varchar(50),
    @NCOA_COA_STATE varchar(50),
    @NCOA_COA_ZIP varchar(50),
    @NCOA_COA_ZIP4 varchar(50),
    @NCOA_COA_DPBC varchar(50),
    @NCOA_COA_CHKDGT varchar(50),
    @NCOA_COA_CART varchar(50),
    @NCOA_COA_LOT varchar(50),
    @NCOA_COA_LOTORD varchar(50),
    @NCOA_COA_URB varchar(50),
    @NCOA_COA_Z4LOM varchar(50),
    @NCOA_COA_ACTION varchar(50),
    @NCOA_COA_QNAME varchar(50),
    @NCOA_DPV_AA varchar(50),
    @NCOA_DPV_A1 varchar(50),
    @NCOA_DPV_BB varchar(50),
    @NCOA_DPV_CC varchar(50),
    @NCOA_DPV_M1 varchar(50),
    @NCOA_DPV_M3 varchar(50),
    @NCOA_DPV_N1 varchar(50),
    @NCOA_DPV_P1 varchar(50),
    @NCOA_DPV_P3 varchar(50),
    @NCOA_DPV_RR varchar(50),
    @NCOA_DPV_R1 varchar(50),
    @NCOA_DPV_STATUS varchar(50),
    @NCOA_DPV_F1 varchar(50),
    @NCOA_DPV_G1 varchar(50),
    @NCOA_DPV_U1 varchar(50),
    @SalesID int;
    DECLARE Sales_Cursor CURSOR FOR
    SELECT * from FLATFILE_SALES;
    OPEN Sales_Cursor
    FETCH NEXT FROM Sales_Cursor
    INTO @FileType ,
    @ACDealerID ,
    @ClientDealerID ,
    @DMSType ,
    @DealNumber ,
    @CustomerNumber ,
    @CustomerName ,
    @CustomerFirstName ,
    @CustomerLastName ,
    @CustomerAddress ,
    @CustomerCity ,
    @CustomerState ,
    @CustomerZip ,
    @CustomerCounty ,
    @CustomerHomePhone ,
    @CustomerWorkPhone ,
    @CustomerCellPhone ,
    @CustomerPagerPhone ,
    @CustomerEmail ,
    @CustomerBirthDate ,
    @MailBlock ,
    @CoBuyerName ,
    @CoBuyerFirstName ,
    @CoBuyerLastName ,
    @CoBuyerAddress ,
    @CoBuyerCity ,
    @CoBuyerState ,
    @CoBuyerZip ,
    @CoBuyerCounty ,
    @CoBuyerHomePhone ,
    @CoBuyerWorkPhone ,
    @CoBuyerBirthDate ,
    @Salesman_1_Number ,
    @Salesman_1_Name ,
    @Salesman_2_Number ,
    @Salesman_2_Name ,
    @ClosingManagerName ,
    @ClosingManagerNumber ,
    @F_AND_I_ManagerNumber ,
    @F_AND_I_ManagerName ,
    @SalesManagerNumber ,
    @SalesManagerName ,
    @EntryDate ,
    @DealBookDate ,
    @VehicleYear ,
    @VehicleMake ,
    @VehicleModel ,
    @VehicleStockNumber ,
    @VehicleVIN ,
    @VehicleExteriorColor ,
    @VehicleInteriorColor ,
    @VehicleMileage ,
    @VehicleType ,
    @InServiceDate ,
    @HoldBackAmount ,
    @DealType ,
    @SaleType ,
    @BankCode ,
    @BankName ,
    @SalesmanCommission ,
    @GrossProfitSale ,
    @FinanceReserve ,
    @CreditLifePremium ,
    @CreditLifeCommision ,
    @TotalInsuranceReserve ,
    @BalloonAmount ,
    @CashPrice ,
    @AmountFinanced ,
    @TotalOfPayments ,
    @MSRP ,
    @DownPayment ,
    @SecurityDesposit ,
    @Rebate ,
    @Term ,
    @RetailPayment ,
    @PaymentType ,
    @RetailFirstPayDate ,
    @LeaseFirstPayDate ,
    @DayToFirstPayment ,
    @LeaseAnnualMiles ,
    @MileageRate ,
    @APRRate ,
    @ResidualAmount ,
    @LicenseFee ,
    @RegistrationFee ,
    @TotalTax ,
    @ExtendedWarrantyName ,
    @ExtendedWarrantyTerm ,
    @ExtendedWarrantyLimitMiles ,
    @ExtendedWarrantyDollar ,
    @ExtendedWarrantyProfit ,
    @FrontGross ,
    @BackGross ,
    @TradeIn_1_VIN ,
    @TradeIn_2_VIN ,
    @TradeIn_1_Make ,
    @TradeIn_2_Make ,
    @TradeIn_1_Model ,
    @TradeIn_2_Model ,
    @TradeIn_1_ExteriorColor ,
    @TradeIn_2_ExteriorColor ,
    @TradeIn_1_Year ,
    @TradeIn_2_Year ,
    @TradeIn_1_Mileage ,
    @TradeIn_2_Mileage ,
    @TradeIn_1_Gross ,
    @TradeIn_2_Gross ,
    @TradeIn_1_Payoff ,
    @TradeIn_2_Payoff ,
    @TradeIn_1_ACV ,
    @TradeIn_2_ACV ,
    @Fee_1_Name ,
    @Fee_1_Fee ,
    @Fee_1_Commission ,
    @Fee_2_Name ,
    @Fee_2_Fee ,
    @Fee_2_Commission ,
    @Fee_3_Name ,
    @Fee_3_Fee ,
    @Fee_3_Commission ,
    @Fee_4_Name ,
    @Fee_4_Fee ,
    @Fee_4_Commission ,
    @Fee_5_Name ,
    @Fee_5_Fee ,
    @Fee_5_Commission ,
    @Fee_6_Name ,
    @Fee_6_Fee ,
    @Fee_6_Commission ,
    @Fee_7_Name ,
    @Fee_7_Fee ,
    @Fee_7_Commission ,
    @Fee_8_Name ,
    @Fee_8_Fee ,
    @Fee_8_Commission ,
    @Fee_9_Name ,
    @Fee_9_Fee ,
    @Fee_9_Commission ,
    @Fee_10_Name ,
    @Fee_10_Fee ,
    @Fee_10_Commission ,
    @ContractDate ,
    @InsuranceName ,
    @InsuranceAgentName ,
    @InsuranceAddress ,
    @InsuranceCity ,
    @InsuranceState ,
    @InsuranceZip ,
    @InsurancePhone ,
    @InsurancePolicyNumber ,
    @InsuranceEffectiveDate ,
    @InsuranceExpirationDate ,
    @InsuranceCompensationDeduction ,
    @TradeIn_1_InteriorColor ,
    @TradeIn_2_InteriorColor ,
    @PhoneBlock ,
    @LicensePlateNumber ,
    @Cost ,
    @InvoiceAmount ,
    @FinanceCharge ,
    @TotalPickupPayment ,
    @TotalAccessories ,
    @TotalDriveOffAmount ,
    @EmailBlock ,
    @ModelDescriptionOfCarSold ,
    @VehicleClassification ,
    @ModelNumberOfCarSold ,
    @GAPPremium ,
    @LastInstallmentDate ,
    @CashDeposit ,
    @AHPremium ,
    @LeaseRate ,
    @DealerSelect ,
    @LeasePayment ,
    @LeaseNetCapCost ,
    @LeaseTotalCapReduction ,
    @DealStatus ,
    @CustomerSuffix ,
    @CustomerSalutation ,
    @CustomerAddress2 ,
    @CustomerMiddleName ,
    @GlobalOptOut ,
    @LeaseTerm ,
    @ExtendedWarrantyFlag ,
    @Salesman_3_Number ,
    @Salesman_3_Name ,
    @Salesman_4_Number ,
    @Salesman_4_Name ,
    @Salesman_5_Number ,
    @Salesman_5_Name ,
    @Salesman_6_Number ,
    @Salesman_6_Name ,
    @APRRate2 ,
    @APRRate3 ,
    @APRRate4 ,
    @Term2 ,
    @SecurityDeposit2 ,
    @DownPayment2 ,
    @TotalOfPayments2 ,
    @BasePayment ,
    @JournalSaleAmount ,
    @IndividualBusinessFlag ,
    @InventoryDate ,
    @StatusDate ,
    @ListPrice ,
    @NetTradeAmount ,
    @TrimLevel ,
    @SubTrimLevel ,
    @BodyDescription ,
    @BodyDoorCount ,
    @TransmissionDesc ,
    @EngineDesc ,
    @TypeCode ,
    @SLCT2 ,
    @DealDateOffset ,
    @AccountingDate ,
    @CoBuyerCustNum ,
    @CoBuyerCell ,
    @CoBuyerEmail ,
    @CoBuyerSalutation ,
    @CoBuyerPhoneBlock ,
    @CoBuyerMailBlock ,
    @CoBuyerEmailBlock ,
    @RealBookDate ,
    @CoBuyerMiddleName ,
    @CoBuyerCountry ,
    @CoBuyerAddress2 ,
    @CoBuyerOptOut ,
    @CoBuyerOccupation ,
    @CoBuyerEmployer ,
    @Country ,
    @Occupation ,
    @Employer ,
    @Salesman2Commission ,
    @BankAddress ,
    @BankCity ,
    @BankState ,
    @BankZip ,
    @LeaseEstimatedMiles ,
    @AFTReserve ,
    @CreditLifePrem ,
    @CreditLifeRes ,
    @AHRes ,
    @Language ,
    @BuyRate ,
    @DMVAmount ,
    @Weight ,
    @StateDMVTotFee ,
    @ROSNumber ,
    @Incentives ,
    @CASS_STD_LINE1 ,
    @CASS_STD_LINE2 ,
    @CASS_STD_CITY ,
    @CASS_STD_STATE ,
    @CASS_STD_ZIP ,
    @CASS_STD_ZIP4 ,
    @CASS_STD_DPBC ,
    @CASS_STD_CHKDGT ,
    @CASS_STD_CART ,
    @CASS_STD_LOT ,
    @CASS_STD_LOTORD ,
    @CASS_STD_URB ,
    @CASS_STD_FIPS ,
    @CASS_STD_EWS ,
    @CASS_STD_LACS ,
    @CASS_STD_ZIPMOV ,
    @CASS_STD_Z4LOM ,
    @CASS_STD_NDIAPT ,
    @CASS_STD_NDIRR ,
    @CASS_STD_LACSRT ,
    @CASS_STD_ERROR_CD ,
    @NCOA_AC_ID ,
    @NCOA_COA_ADDSRC ,
    @NCOA_COA_MATCH ,
    @NCOA_COA_MOVTYP ,
    @NCOA_COA_DATE ,
    @NCOA_COA_DELCD ,
    @NCOA_COA_RTYPE ,
    @NCOA_COA_RTNCD ,
    @NCOA_COA_LINE1 ,
    @NCOA_COA_LINE2 ,
    @NCOA_COA_CITY ,
    @NCOA_COA_STATE ,
    @NCOA_COA_ZIP ,
    @NCOA_COA_ZIP4 ,
    @NCOA_COA_DPBC ,
    @NCOA_COA_CHKDGT ,
    @NCOA_COA_CART ,
    @NCOA_COA_LOT ,
    @NCOA_COA_LOTORD ,
    @NCOA_COA_URB ,
    @NCOA_COA_Z4LOM ,
    @NCOA_COA_ACTION ,
    @NCOA_COA_QNAME ,
    @NCOA_DPV_AA ,
    @NCOA_DPV_A1 ,
    @NCOA_DPV_BB ,
    @NCOA_DPV_CC ,
    @NCOA_DPV_M1 ,
    @NCOA_DPV_M3 ,
    @NCOA_DPV_N1 ,
    @NCOA_DPV_P1 ,
    @NCOA_DPV_P3 ,
    @NCOA_DPV_RR ,
    @NCOA_DPV_R1 ,
    @NCOA_DPV_STATUS ,
    @NCOA_DPV_F1 ,
    @NCOA_DPV_G1 ,
    @NCOA_DPV_U1 ;
    WHILE @@FETCH_STATUS = 0
    BEGIN
    PRINT @VehicleVIN ;
    --===============================================================================
    -- ****************** insert into Sales Table ***********
    INSERT INTO Sales
    IconicDealerID,
    DealNumber,
    CustomerNumber,
    DMSType,
    ContractDate
    VALUES (@ClientDealerID,@DealNumber,@CustomerNumber,@DMSType,@ContractDate);
    set @SalesID = scope_identity();
    PRINT @SalesID;
    --================================================================================
    --Insert into SALES_TRADEIN Table
    INSERT INTO SALES_TRADEIN
    SalesID,
    TradeIn_VIN,
    TradeIn_Make,
    TradeIn_Model,
    TradeIn_ExteriorColor,
    TradeIn_Year,
    TradeIn_Mileage,
    TradeIn_Gross,
    TradeIn_Payoff,
    TradeIn_ACV,
    TradeIn_InteriorColor
    VALUES (
    @SalesID,
    case when @TradeIn_1_VIN null then @TradeIn_1_VIN else @TradeIn_2_VIN end,
    case when @TradeIn_1_Make is null then @TradeIn_1_Make else @TradeIn_2_Make end,
    case when @TradeIn_1_Model is null then @TradeIn_1_Model else @TradeIn_2_Model end,
    case when @TradeIn_1_ExteriorColor is null then @TradeIn_1_ExteriorColor else @TradeIn_2_ExteriorColor end,
    case when @TradeIn_1_Year is null then @TradeIn_1_Year else @TradeIn_2_Year end,
    case when @TradeIn_1_Mileage is null then @TradeIn_1_Mileage else @TradeIn_2_Mileage end,
    case when @TradeIn_1_Gross is null then @TradeIn_1_Gross else @TradeIn_2_Gross end,
    case when @TradeIn_1_Payoff is not null then @TradeIn_1_Payoff else @TradeIn_2_Payoff end,
    case when @TradeIn_1_ACV is null then @TradeIn_1_ACV else @TradeIn_2_ACV end,
    case when @TradeIn_1_InteriorColor is null then @TradeIn_1_InteriorColor else @TradeIn_1_InteriorColor end
    --===============================================================================
    --Insert into SALES_VEHICLE Table
    INSERT INTO SALES_VEHICLE
    SalesID ,
    VehicleYear ,
    VehicleMake ,
    VehicleModel ,
    VehicleStockNumber ,
    VehicleVIN ,
    VehicleExteriorColor ,
    VehicleInteriorColor ,
    VehicleMileage ,
    VehicleType ,
    InServiceDate ,
    LeaseAnnualMiles ,
    ExtendedWarrantyName ,
    ExtendedWarrantyTerm ,
    ExtendedWarrantyLimitMiles ,
    LicensePlateNumber ,
    ModelDescriptionOfCarSold ,
    VehicleClassification ,
    ModelNumberOfCarSold ,
    ExtendedWarrantyFlag ,
    TrimLevel ,
    SubTrimLevel ,
    BodyDescription ,
    BodyDoorCount ,
    TransmissionDesc ,
    EngineDesc ,
    TypeCode ,
    Weight ,
    LeaseEstimatedMiles
    VALUES (
    @SalesID,@VehicleYear,@VehicleMake,@VehicleModel,@VehicleStockNumber,@VehicleVIN,
    @VehicleExteriorColor,@VehicleInteriorColor,@VehicleMileage,@VehicleType,
    @InServiceDate,@LeaseAnnualMiles,@ExtendedWarrantyName,@ExtendedWarrantyTerm,
    @ExtendedWarrantyLimitMiles,@LicensePlateNumber,@ModelDescriptionOfCarSold,
    @VehicleClassification,@ModelNumberOfCarSold,@ExtendedWarrantyFlag,
    @TrimLevel,@SubTrimLevel,@BodyDescription,@BodyDoorCount,
    @TransmissionDesc,@EngineDesc,@TypeCode,@Weight,@LeaseEstimatedMiles
    --======================================================================================
    --Insert into SALES_FEE Table
    INSERT INTO SALES_FEE
    SalesID ,
    Fee_Name ,
    Fee_Fee ,
    Fee_Commission
    VALUES (
    @SalesID,
    case
    when @Fee_1_Name is not null then @Fee_1_Name
    when @Fee_2_Name is not null then @Fee_2_Name
    when @Fee_3_Name is not null then @Fee_3_Name
    when @Fee_4_Name is not null then @Fee_4_Name
    when @Fee_5_Name is not null then @Fee_5_Name
    when @Fee_6_Name is not null then @Fee_6_Name
    when @Fee_7_Name is not null then @Fee_7_Name
    when @Fee_8_Name is not null then @Fee_8_Name
    when @Fee_9_Name is not null then @Fee_9_Name
    else @Fee_10_Name end,
    case
    when @Fee_1_Fee is not null then @Fee_1_Fee
    when @Fee_2_Fee is not null then @Fee_2_Fee
    when @Fee_3_Fee is not null then @Fee_3_Fee
    when @Fee_4_Fee is not null then @Fee_4_Fee
    when @Fee_5_Fee is not null then @Fee_5_Fee
    when @Fee_6_Fee is not null then @Fee_6_Fee
    when @Fee_7_Fee is not null then @Fee_7_Fee
    when @Fee_8_Fee is not null then @Fee_8_Fee
    when @Fee_9_Fee is not null then @Fee_9_Fee
    else @Fee_10_Fee end,
    case
    when @Fee_1_Commission is not null then @Fee_1_Commission
    when @Fee_2_Commission is not null then @Fee_2_Commission
    when @Fee_3_Commission is not null then @Fee_3_Commission
    when @Fee_4_Commission is not null then @Fee_4_Commission
    when @Fee_5_Commission is not null then @Fee_5_Commission
    when @Fee_6_Commission is not null then @Fee_6_Commission
    when @Fee_7_Commission is not null then @Fee_7_Commission
    when @Fee_8_Commission is not null then @Fee_8_Commission
    when @Fee_9_Commission is not null then @Fee_9_Commission
    else @Fee_10_Commission end
    --======================================================================================
    --Insert into SALES_HR Table
    INSERT INTO SALES_HR
    SalesID ,
    Salesman_Number ,
    Salesman_Name ,
    ClosingManagerName ,
    ClosingManagerNumber ,
    F_AND_I_ManagerNumber ,
    F_AND_I_ManagerName ,
    SalesManagerNumber ,
    SalesManagerName
    VALUES (
    @SalesID ,
    case
    when @Salesman_1_Number is not null then @Salesman_1_Number
    when @Salesman_2_Number is not null then @Salesman_2_Number
    when @Salesman_3_Number is not null then @Salesman_3_Number
    when @Salesman_4_Number is not null then @Salesman_4_Number
    when @Salesman_5_Number is not null then @Salesman_5_Number
    else @Salesman_6_Number end,
    case
    when @Salesman_1_Name is not null then @Salesman_1_Name
    when @Salesman_2_Name is not null then @Salesman_2_Name
    when @Salesman_3_Name is not null then @Salesman_3_Name
    when @Salesman_4_Name is not null then @Salesman_4_Name
    when @Salesman_5_Name is not null then @Salesman_5_Name
    else @Salesman_6_Name end,
    @ClosingManagerName ,
    @ClosingManagerNumber ,
    @F_AND_I_ManagerNumber ,
    @F_AND_I_ManagerName ,
    @SalesManagerNumber ,
    @SalesManagerName
    --======================================================================================
    --Insert into SALES_COBUYER Table
    INSERT INTO SALES_COBUYER
    SalesID ,
    CoBuyerName ,
    CoBuyerFirstName ,
    CoBuyerLastName ,
    CoBuyerAddress ,
    CoBuyerCity ,
    CoBuyerState ,
    CoBuyerZip ,
    CoBuyerCounty ,
    CoBuyerHomePhone ,
    CoBuyerWorkPhone ,
    CoBuyerBirthDate ,
    CoBuyerCustNum ,
    CoBuyerCell ,
    CoBuyerEmail ,
    CoBuyerSalutation ,
    CoBuyerMiddleName ,
    CoBuyerCountry ,
    CoBuyerAddress2 ,
    CoBuyerOptOut ,
    CoBuyerOccupation ,
    CoBuyerEmployer ,
    CoBuyerPhoneBlock ,
    CoBuyerMailBlock ,
    CoBuyerEmailBlock
    VALUES (
    @SalesID,@CoBuyerName,@CoBuyerFirstName,@CoBuyerLastName,@CoBuyerAddress,
    @CoBuyerCity,@CoBuyerState,@CoBuyerZip,@CoBuyerCounty,@CoBuyerHomePhone,
    @CoBuyerWorkPhone,@CoBuyerBirthDate,@CoBuyerCustNum,@CoBuyerCell,
    @CoBuyerEmail,@CoBuyerSalutation,@CoBuyerMiddleName,@CoBuyerCountry,
    @CoBuyerAddress2,@CoBuyerOptOut,@CoBuyerOccupation,@CoBuyerEmployer,
    @CoBuyerPhoneBlock,@CoBuyerMailBlock,@CoBuyerEmailBlock
    --======================================================================================
    --Insert into SALES_CUSTOMER Table
    INSERT INTO SALES_CUSTOMER
    SalesID ,
    IndividualBusinessFlag ,
    PhoneBlock ,
    EmailBlock ,
    CustomerName ,
    CustomerFirstName ,
    CustomerLastName ,
    CustomerAddress ,
    CustomerCity ,
    CustomerState ,
    CustomerZip ,
    CustomerCounty ,
    CustomerHomePhone ,
    CustomerWorkPhone ,
    CustomerCellPhone ,
    CustomerPagerPhone ,
    CustomerEmail ,
    CustomerBirthDate ,
    MailBlock ,
    CustomerSuffix ,
    CustomerSalutation ,
    CustomerAddress2 ,
    CustomerMiddleName ,
    GlobalOptOut ,
    InsuranceName ,
    InsuranceAgentName ,
    InsuranceAddress ,
    InsuranceCity ,
    InsuranceState ,
    InsuranceZip ,
    InsurancePhone ,
    InsurancePolicyNumber ,
    InsuranceEffectiveDate ,
    InsuranceExpirationDate ,
    InsuranceCompensationDeduction ,
    Country ,
    Occupation ,
    Employer ,
    CASS_STD_LINE1 ,
    CASS_STD_LINE2 ,
    CASS_STD_CITY ,
    CASS_STD_STATE ,
    CASS_STD_ZIP ,
    CASS_STD_ZIP4 ,
    CASS_STD_DPBC ,
    CASS_STD_CHKDGT ,
    CASS_STD_CART ,
    CASS_STD_LOT ,
    CASS_STD_LOTORD ,
    CASS_STD_URB ,
    CASS_STD_FIPS ,
    CASS_STD_EWS ,
    CASS_STD_LACS ,
    CASS_STD_ZIPMOV ,
    CASS_STD_Z4LOM ,
    CASS_STD_NDIAPT ,
    CASS_STD_NDIRR ,
    CASS_STD_LACSRT ,
    CASS_STD_ERROR_CD ,
    NCOA_AC_ID ,
    NCOA_COA_ADDSRC ,
    NCOA_COA_MATCH ,
    NCOA_COA_MOVTYP ,
    NCOA_COA_DATE ,
    NCOA_COA_DELCD ,
    NCOA_COA_RTYPE ,
    NCOA_COA_RTNCD ,
    NCOA_COA_LINE1 ,
    NCOA_COA_LINE2 ,
    NCOA_COA_CITY ,
    NCOA_COA_STATE ,
    NCOA_COA_ZIP ,
    NCOA_COA_ZIP4 ,
    NCOA_COA_DPBC ,
    NCOA_COA_CHKDGT ,
    NCOA_COA_CART ,
    NCOA_COA_LOT ,
    NCOA_COA_LOTORD ,
    NCOA_COA_URB ,
    NCOA_COA_Z4LOM ,
    NCOA_COA_ACTION ,
    NCOA_COA_QNAME ,
    NCOA_DPV_AA ,
    NCOA_DPV_A1 ,
    NCOA_DPV_BB ,
    NCOA_DPV_CC ,
    NCOA_DPV_M1 ,
    NCOA_DPV_M3 ,
    NCOA_DPV_N1 ,
    NCOA_DPV_P1 ,
    NCOA_DPV_P3 ,
    NCOA_DPV_RR ,
    NCOA_DPV_R1 ,
    NCOA_DPV_STATUS ,
    NCOA_DPV_F1 ,
    NCOA_DPV_G1 ,
    NCOA_DPV_U1
    VALUES (
    @SalesID ,
    @IndividualBusinessFlag ,
    @PhoneBlock ,
    @EmailBlock ,
    @CustomerName ,
    @CustomerFirstName ,
    @CustomerLastName ,
    @CustomerAddress ,
    @CustomerCity ,
    @CustomerState ,
    @CustomerZip ,
    @CustomerCounty ,
    @CustomerHomePhone ,
    @CustomerWorkPhone ,
    @CustomerCellPhone ,
    @CustomerPagerPhone ,
    @CustomerEmail ,
    @CustomerBirthDate ,
    @MailBlock ,
    @CustomerSuffix ,
    @CustomerSalutation ,
    @CustomerAddress2 ,
    @CustomerMiddleName ,
    @GlobalOptOut ,
    @InsuranceName ,
    @InsuranceAgentName ,
    @InsuranceAddress ,
    @InsuranceCity ,
    @InsuranceState ,
    @InsuranceZip ,
    @InsurancePhone ,
    @InsurancePolicyNumber ,
    @InsuranceEffectiveDate ,
    @InsuranceExpirationDate ,
    @InsuranceCompensationDeduction ,
    @Country ,
    @Occupation ,
    @Employer ,
    @CASS_STD_LINE1 ,
    @CASS_STD_LINE2 ,
    @CASS_STD_CITY ,
    @CASS_STD_STATE ,
    @CASS_STD_ZIP ,
    @CASS_STD_ZIP4 ,
    @CASS_STD_DPBC ,
    @CASS_STD_CHKDGT ,
    @CASS_STD_CART ,
    @CASS_STD_LOT ,
    @CASS_STD_LOTORD ,
    @CASS_STD_URB ,
    @CASS_STD_FIPS ,
    @CASS_STD_EWS ,
    @CASS_STD_LACS ,
    @CASS_STD_ZIPMOV ,
    @CASS_STD_Z4LOM ,
    @CASS_STD_NDIAPT ,
    @CASS_STD_NDIRR ,
    @CASS_STD_LACSRT ,
    @CASS_STD_ERROR_CD ,
    @NCOA_AC_ID ,
    @NCOA_COA_ADDSRC ,
    @NCOA_COA_MATCH ,
    @NCOA_COA_MOVTYP ,
    @NCOA_COA_DATE ,
    @NCOA_COA_DELCD ,
    @NCOA_COA_RTYPE ,
    @NCOA_COA_RTNCD ,
    @NCOA_COA_LINE1 ,
    @NCOA_COA_LINE2 ,
    @NCOA_COA_CITY ,
    @NCOA_COA_STATE ,
    @NCOA_COA_ZIP ,
    @NCOA_COA_ZIP4 ,
    @NCOA_COA_DPBC ,
    @NCOA_COA_CHKDGT ,
    @NCOA_COA_CART ,
    @NCOA_COA_LOT ,
    @NCOA_COA_LOTORD ,
    @NCOA_COA_URB ,
    @NCOA_COA_Z4LOM ,
    @NCOA_COA_ACTION ,
    @NCOA_COA_QNAME ,
    @NCOA_DPV_AA ,
    @NCOA_DPV_A1 ,
    @NCOA_DPV_BB ,
    @NCOA_DPV_CC ,
    @NCOA_DPV_M1 ,
    @NCOA_DPV_M3 ,
    @NCOA_DPV_N1 ,
    @NCOA_DPV_P1 ,
    @NCOA_DPV_P3 ,
    @NCOA_DPV_RR ,
    @NCOA_DPV_R1 ,
    @NCOA_DPV_STATUS ,
    @NCOA_DPV_F1 ,
    @NCOA_DPV_G1 ,
    @NCOA_DPV_U1
    --======================================================================================
    --Insert into SALES_AMOUNT Table
    INSERT INTO SALES_AMOUNT
    SalesID ,
    HoldBackAmount ,
    ExtendedWarrantyDollar ,
    ExtendedWarrantyProfit ,
    FrontGross ,
    BackGross ,
    MileageRate ,
    APRRate ,
    ResidualAmount ,
    LicenseFee ,
    RegistrationFee ,
    TotalTax ,
    Cost ,
    InvoiceAmount ,
    FinanceCharge ,
    TotalPickupPayment ,
    TotalAccessories ,
    TotalDriveOffAmount ,
    SalesmanCommission ,
    GrossProfitSale ,
    FinanceReserve ,
    CreditLifePremium ,
    CreditLifeCommision ,
    TotalInsuranceReserve ,
    BalloonAmount ,
    CashPrice ,
    AmountFinanced ,
    TotalOfPayments ,
    MSRP ,
    DownPayment ,
    SecurityDesposit ,
    Rebate ,
    Term ,
    RetailPayment ,
    LeasePayment ,
    LeaseNetCapCost ,
    LeaseTotalCapReduction ,
    APRRate2 ,
    APRRate3 ,
    GAPPremium ,
    LeaseTerm ,
    CashDeposit ,
    AHPremium ,
    LeaseRate ,
    Incentives ,
    StateDMVTotFee ,
    BuyRate ,
    DMVAmount ,
    CreditLifePrem ,
    CreditLifeRes ,
    AHRes ,
    Salesman2Commission ,
    ListPrice ,
    NetTradeAmount ,
    APRRate4 ,
    Term2 ,
    SecurityDeposit2 ,
    DownPayment2 ,
    TotalOfPayments2 ,
    BasePayment ,
    JournalSaleAmount
    VALUES (
    @SalesID,@HoldBackAmount,@ExtendedWarrantyDollar,@ExtendedWarrantyProfit,
    @FrontGross,@BackGross,@MileageRate,@APRRate,@ResidualAmount,@LicenseFee,
    @RegistrationFee,@TotalTax,@Cost,@InvoiceAmount,@FinanceCharge,
    @TotalPickupPayment,@TotalAccessories,@TotalDriveOffAmount,@SalesmanCommission,
    @GrossProfitSale,@FinanceReserve,@CreditLifePremium,@CreditLifeCommision,
    @TotalInsuranceReserve,@BalloonAmount,@CashPrice,@AmountFinanced,@TotalOfPayments,
    @MSRP,@DownPayment,@SecurityDesposit,@Rebate,@Term,@RetailPayment,@LeasePayment,
    @LeaseNetCapCost,@LeaseTotalCapReduction,@APRRate2,@APRRate3,@GAPPremium,
    @LeaseTerm,@CashDeposit,@AHPremium,@LeaseRate,@Incentives,@StateDMVTotFee,
    @BuyRate,@DMVAmount,@CreditLifePrem,@CreditLifeRes,@AHRes,@Salesman2Commission,
    @ListPrice,@NetTradeAmount,@APRRate4,@Term2,@SecurityDeposit2,
    @DownPayment2,@TotalOfPayments2,@BasePayment,@JournalSaleAmount
    --===========================================================================
    --Insert into SALES_BANKINFO Table
    INSERT INTO SALES_BANKINFO
    SalesID ,
    SLCT2 ,
    DealDateOffset ,
    DealerSelect ,
    DealStatus ,
    DealType ,
    SaleType ,
    BankCode ,
    BankName ,
    PaymentType ,
    BankAddress ,
    BankCity ,
    BankState ,
    BankZip ,
    AFTReserve ,
    Language ,
    ROSNumber
    VALUES (
    @SalesID,@SLCT2,@DealDateOffset,@DealerSelect,@DealStatus,@DealType,
    @SaleType,@BankCode,@BankName,@PaymentType,@BankAddress,@BankCity,
    @BankState,@BankZip,@AFTReserve,@Language,@ROSNumber
    ---=======================================================
    INSERT INTO SALES_DATE
    SalesID ,
    AccountingDate ,
    InventoryDate ,
    StatusDate ,
    LastInstallmentDate ,
    RetailFirstPayDate ,
    LeaseFirstPayDate ,
    DayToFirstPayment ,
    EntryDate ,
    DealBookDate ,
    RealBookDate
    VALUES (
    @SalesID ,
    convert (datetime,@AccountingDate) ,
    -- CAST (@AccountingDate AS datetime),
    convert (datetime,@InventoryDate) ,
    -- CAST (@InventoryDate AS datetime),
    convert (datetime,@StatusDate) ,
    -- CAST (@StatusDate AS datetime),
    convert (datetime,@LastInstallmentDate),
    -- CAST (@LastInstallmentDate AS datetime),
    convert (datetime,@RetailFirstPayDate) ,
    -- CAST (@RetailFirstPayDate AS datetime),
    @LeaseFirstPayDate ,
    convert (datetime,@DayToFirstPayment),
    -- CAST (@DayToFirstPayment AS datetime),
    convert (datetime,@EntryDate),
    -- CAST (@EntryDate AS datetime),
    convert (datetime,@DealBookDate),
    -- CAST (@DealBookDate AS datetime),
    convert (datetime,@RealBookDate)
    -- CAST (@RealBookDate AS datetime)
    */---=======================================================
    --======================================================================================
    -- Move cursor to Next record
    FETCH NEXT FROM Sales_Cursor
    INTO @FileType ,
    @ACDealerID ,
    @ClientDealerID ,
    @DMSType ,
    @DealNumber ,
    @CustomerNumber ,
    @CustomerName ,
    @CustomerFirstName ,
    @CustomerLastName ,
    @CustomerAddress ,
    @CustomerCity ,
    @CustomerState ,
    @CustomerZip ,
    @CustomerCounty ,
    @CustomerHomePhone ,
    @CustomerWorkPhone ,
    @CustomerCellPhone ,
    @CustomerPagerPhone ,
    @CustomerEmail ,
    @CustomerBirthDate ,
    @MailBlock ,
    @CoBuyerName ,
    @CoBuyerFirstName ,
    @CoBuyerLastName ,
    @CoBuyerAddress ,
    @CoBuyerCity ,
    @CoBuyerState ,
    @CoBuyerZip ,
    @CoBuyerCounty ,
    @CoBuyerHomePhone ,
    @CoBuyerWorkPhone ,
    @CoBuyerBirthDate ,
    @Salesman_1_Number ,
    @Salesman_1_Name ,
    @Salesman_2_Number ,
    @Salesman_2_Name ,
    @ClosingManagerName ,
    @ClosingManagerNumber ,
    @F_AND_I_ManagerNumber ,
    @F_AND_I_ManagerName ,
    @SalesManagerNumber ,
    @SalesManagerName ,
    @EntryDate ,
    @DealBookDate ,
    @VehicleYear ,
    @VehicleMake ,
    @VehicleModel ,
    @VehicleStockNumber ,
    @VehicleVIN ,
    @VehicleExteriorColor ,
    @VehicleInteriorColor ,
    @VehicleMileage ,
    @VehicleType ,
    @InServiceDate ,
    @HoldBackAmount ,
    @DealType ,
    @SaleType ,
    @BankCode ,
    @BankName ,
    @SalesmanCommission ,
    @GrossProfitSale ,
    @FinanceReserve ,
    @CreditLifePremium ,
    @CreditLifeCommision ,
    @TotalInsuranceReserve ,
    @BalloonAmount ,
    @CashPrice ,
    @AmountFinanced ,
    @TotalOfPayments ,
    @MSRP ,
    @DownPayment ,
    @SecurityDesposit ,
    @Rebate ,
    @Term ,
    @RetailPayment ,
    @PaymentType ,
    @RetailFirstPayDate ,
    @LeaseFirstPayDate ,
    @DayToFirstPayment ,
    @LeaseAnnualMiles ,
    @MileageRate ,
    @APRRate ,
    @ResidualAmount ,
    @LicenseFee ,
    @RegistrationFee ,
    @TotalTax ,
    @ExtendedWarrantyName ,
    @ExtendedWarrantyTerm ,
    @ExtendedWarrantyLimitMiles ,
    @ExtendedWarrantyDollar ,
    @ExtendedWarrantyProfit ,
    @FrontGross ,
    @BackGross ,
    @TradeIn_1_VIN ,
    @TradeIn_2_VIN ,
    @TradeIn_1_Make ,
    @TradeIn_2_Make ,
    @TradeIn_1_Model ,
    @TradeIn_2_Model ,
    @TradeIn_1_ExteriorColor ,
    @TradeIn_2_ExteriorColor ,
    @TradeIn_1_Year ,
    @TradeIn_2_Year ,
    @TradeIn_1_Mileage ,
    @TradeIn_2_Mileage ,
    @TradeIn_1_Gross ,
    @TradeIn_2_Gross ,
    @TradeIn_1_Payoff ,
    @TradeIn_2_Payoff ,
    @TradeIn_1_ACV ,
    @TradeIn_2_ACV ,
    @Fee_1_Name ,
    @Fee_1_Fee ,
    @Fee_1_Commission ,
    @Fee_2_Name ,
    @Fee_2_Fee ,
    @Fee_2_Commission ,
    @Fee_3_Name ,
    @Fee_3_Fee ,
    @Fee_3_Commission ,
    @Fee_4_Name ,
    @Fee_4_Fee ,
    @Fee_4_Commission ,
    @Fee_5_Name ,
    @Fee_5_Fee ,
    @Fee_5_Commission ,
    @Fee_6_Name ,
    @Fee_6_Fee ,
    @Fee_6_Commission ,
    @Fee_7_Name ,
    @Fee_7_Fee ,
    @Fee_7_Commission ,
    @Fee_8_Name ,
    @Fee_8_Fee ,
    @Fee_8_Commission ,
    @Fee_9_Name ,
    @Fee_9_Fee ,
    @Fee_9_Commission ,
    @Fee_10_Name ,
    @Fee_10_Fee ,
    @Fee_10_Commission ,
    @ContractDate ,
    @InsuranceName ,
    @InsuranceAgentName ,
    @InsuranceAddress ,
    @InsuranceCity ,
    @InsuranceState ,
    @InsuranceZip ,
    @InsurancePhone ,
    @InsurancePolicyNumber ,
    @InsuranceEffectiveDate ,
    @InsuranceExpirationDate ,
    @InsuranceCompensationDeduction ,
    @TradeIn_1_InteriorColor ,
    @TradeIn_2_InteriorColor ,
    @PhoneBlock ,
    @LicensePlateNumber ,
    @Cost ,
    @InvoiceAmount ,
    @FinanceCharge ,
    @TotalPickupPayment ,
    @TotalAccessories ,
    @TotalDriveOffAmount ,
    @EmailBlock ,
    @ModelDescriptionOfCarSold ,
    @VehicleClassification ,
    @ModelNumberOfCarSold ,
    @GAPPremium ,
    @LastInstallmentDate ,
    @CashDeposit ,
    @AHPremium ,
    @LeaseRate ,
    @DealerSelect ,
    @LeasePayment ,
    @LeaseNetCapCost ,
    @LeaseTotalCapReduction ,
    @DealStatus ,
    @CustomerSuffix ,
    @CustomerSalutation ,
    @CustomerAddress2 ,
    @CustomerMiddleName ,
    @GlobalOptOut ,
    @LeaseTerm ,
    @ExtendedWarrantyFlag ,
    @Salesman_3_Number ,
    @Salesman_3_Name ,
    @Salesman_4_Number ,
    @Salesman_4_Name ,
    @Salesman_5_Number ,
    @Salesman_5_Name ,
    @Salesman_6_Number ,
    @Salesman_6_Name ,
    @APRRate2 ,
    @APRRate3 ,
    @APRRate4 ,
    @Term2 ,
    @SecurityDeposit2 ,
    @DownPayment2 ,
    @TotalOfPayments2 ,
    @BasePayment ,
    @JournalSaleAmount ,
    @IndividualBusinessFlag ,
    @InventoryDate ,
    @StatusDate ,
    @ListPrice ,
    @NetTradeAmount ,
    @TrimLevel ,
    @SubTrimLevel ,
    @BodyDescription ,
    @BodyDoorCount ,
    @TransmissionDesc ,
    @EngineDesc ,
    @TypeCode ,
    @SLCT2 ,
    @DealDateOffset ,
    @AccountingDate ,
    @CoBuyerCustNum ,
    @CoBuyerCell ,
    @CoBuyerEmail ,
    @CoBuyerSalutation ,
    @CoBuyerPhoneBlock ,
    @CoBuyerMailBlock ,
    @CoBuyerEmailBlock ,
    @RealBookDate ,
    @CoBuyerMiddleName ,
    @CoBuyerCountry ,
    @CoBuyerAddress2 ,
    @CoBuyerOptOut ,
    @CoBuyerOccupation ,
    @CoBuyerEmployer ,
    @Country ,
    @Occupation ,
    @Employer ,
    @Salesman2Commission ,
    @BankAddress ,
    @BankCity ,
    @BankState ,
    @BankZip ,
    @LeaseEstimatedMiles ,
    @AFTReserve ,
    @CreditLifePrem ,
    @CreditLifeRes ,
    @AHRes ,
    @Language ,
    @BuyRate ,
    @DMVAmount ,
    @Weight ,
    @StateDMVTotFee ,
    @ROSNumber ,
    @Incentives ,
    @CASS_STD_LINE1 ,
    @CASS_STD_LINE2 ,
    @CASS_STD_CITY ,
    @CASS_STD_STATE ,
    @CASS_STD_ZIP ,
    @CASS_STD_ZIP4 ,
    @CASS_STD_DPBC ,
    @CASS_STD_CHKDGT ,
    @CASS_STD_CART ,
    @CASS_STD_LOT ,
    @CASS_STD_LOTORD ,
    @CASS_STD_URB ,
    @CASS_STD_FIPS ,
    @CASS_STD_EWS ,
    @CASS_STD_LACS ,
    @CASS_STD_ZIPMOV ,
    @CASS_STD_Z4LOM ,
    @CASS_STD_NDIAPT ,
    @CASS_STD_NDIRR ,
    @CASS_STD_LACSRT ,
    @CASS_STD_ERROR_CD ,
    @NCOA_AC_ID ,
    @NCOA_COA_ADDSRC ,
    @NCOA_COA_MATCH ,
    @NCOA_COA_MOVTYP ,
    @NCOA_COA_DATE ,
    @NCOA_COA_DELCD ,
    @NCOA_COA_RTYPE ,
    @NCOA_COA_RTNCD ,
    @NCOA_COA_LINE1 ,
    @NCOA_COA_LINE2 ,
    @NCOA_COA_CITY ,
    @NCOA_COA_STATE ,
    @NCOA_COA_ZIP ,
    @NCOA_COA_ZIP4 ,
    @NCOA_COA_DPBC ,
    @NCOA_COA_CHKDGT ,
    @NCOA_COA_CART ,
    @NCOA_COA_LOT ,
    @NCOA_COA_LOTORD ,
    @NCOA_COA_URB ,
    @NCOA_COA_Z4LOM ,
    @NCOA_COA_ACTION ,
    @NCOA_COA_QNAME ,
    @NCOA_DPV_AA ,
    @NCOA_DPV_A1 ,
    @NCOA_DPV_BB ,
    @NCOA_DPV_CC ,
    @NCOA_DPV_M1 ,
    @NCOA_DPV_M3 ,
    @NCOA_DPV_N1 ,
    @NCOA_DPV_P1 ,
    @NCOA_DPV_P3 ,
    @NCOA_DPV_RR ,
    @NCOA_DPV_R1 ,
    @NCOA_DPV_STATUS ,
    @NCOA_DPV_F1 ,
    @NCOA_DPV_G1 ,
    @NCOA_DPV_U1;
    END
    CLOSE Sales_Cursor;
    DEALLOCATE Sales_Cursor;
    GO
    SET ANSI_PADDING OFF
    GO

    Duplicate thread:
    problem - original

  • Stored Procedure creation issue

    Hi All,
    I need a stored procedure's for below Scenario:
    tblProduct is a parameter table that has values list of Products and every product has code (Eg, PEN A, BOOK B , PENCIL C and so on)
    For every value a procedure sp_findIndex will be called 
    sp_findIndex finds the index of the alphabet based on the tblKeyValue a key value table which has two columns key and value, key 1,2,3....
    and values A,B,C..
    Further sp_findIndex calls sp_evenOdd with
    the index as input and provides an output whether index is an even or an odd number 
    which is printed through sp_findIndex procedure 
    Task 1
    List down even and odd for all the products.
    Task 2
    Now warp this logic to stored procedure sp_wrapper which takes input Product names separated by comma.
    Thanks in Advance.........
    Tbl_Product
    Create table Tbl_Product
    Product varchar(50) NULL,
    Code Varchar (50) NULL
    Insert into Tbl_Product values('PEN','A')
    Insert into Tbl_Product values('BOOK','B')
    Insert into Tbl_Product values('PENCIL','C')
    Insert into Tbl_Product values('TV','D')
    Insert into Tbl_Product values('COMPUTER','E')
    Insert into Tbl_Product values('SHOES','F')
    Insert into Tbl_Product values('SHIRT','G')
    Tab_KeyValue
    Create table tbl_KeyValue
    value char(3) NULL,
    keys int NULL
    Insert into tbl_Keyvalue values('A',1)
    Insert into tbl_Keyvalue values('B',2)
    Insert into tbl_Keyvalue values('C',3)
    Insert into tbl_Keyvalue values('D',4)
    Insert into tbl_Keyvalue values('E',5)
    Insert into tbl_Keyvalue values('F',6)
    Insert into tbl_Keyvalue values('G',7)
    Main
    Procedure:
    CREATE PROCEDURE DBO.SP_WRAPPD
    (PRODUCT1 VARCHAR(1000))
    AS
    BEGIN
    DECLARE @COMMA VARCHAR(2)
    SET @COMMA =','
    SELECT CODE FROM TBL_PRODUCT WHERE CHARINDEX(PRODUCT,@PRODUCT) >0
    END
    Second
    procedure:
    Create Procure sp_findIndexes(@value varchar(10))
    as
    begin
    Declare @keys int
    set @Keys =(select A.keys from tbl_keyvalue A where A.value=@value)
    Declare @Evenodd varchar(10)
    Declare @result int
    Exec @result =sp_EvenOdds @keys
    if @result=1
    set @EvenOdd ='Even'
    else
    set @EvenOdd='Odd'
    insert into ##EvenOddResultss select A.keys,B.Product,@evenodd as evenodd from tbl_product B
    inner join
    tbl_KeyValue A
    on A.Value=B.code and A.keys=@keys
    end
    Third
    Procedure:
    Create procedure sp_EvenOdds (@Key int)
    as
    begin
    if(@key%2=0)
    return(1)
    else
    return(0)
    end
    I am calling third procure from second,second from Main Procedure...
    Thanks in Advance...

    Hi,
    1. Again this is a image and not a code!
    Do you want to waste our time on typing while we can help other people?!?
    Isn't it more helpful to use copy/paste and to bring us a code and not stories/images? 
    2. How can we recreate the issue and execute or even just create this SP without having the relevant elements (like the tables) ?!?
    Please post DDL+DML!
    DDL = Data Definition Language. In our case that is, CREATE TABLE statements for your tables and other definitions that are needed to understand your tables structure and there for let us to test and recreate the problem in our server. Without DDL no one
    can execute any query.
    How to get DDL: Right click on the table in Object Explorer and select script table as CREATE. Post these create table scripts here.
    DML = data manipulation language is a family of queries used for manipulating the data it self like: inserting, deleting and updating data. In our case we need some sample data in order to check the query and get result, so we need some indert query for
    sample data.
    If you post a "create query" for the tables and "insert query" with some sample, then we could help you without Assuming/Guessing. There is a reason that DDL is generally asked for and expected when discussing query problems - it helps
    to identify issues, clarify terminology and prevent incorrect assumptions.  Sample data also provides a common point of reference for the discussion. A script that can be used to illustrate or reproduce the issue you have, will encourage others to help.
    [Personal Site] [Blog] [Facebook]
    Hi Pituach,
    Tbl_Product
    Create table Tbl_Product
    Product varchar(50) NULL,
    Code Varchar (50) NULL
    Insert into Tbl_Product values('PEN','A')
    Insert into Tbl_Product values('BOOK','B')
    Insert into Tbl_Product values('PENCIL','C')
    Insert into Tbl_Product values('TV','D')
    Insert into Tbl_Product values('COMPUTER','E')
    Insert into Tbl_Product values('SHOES','F')
    Insert into Tbl_Product values('SHIRT','G')
    Tab_KeyValue
    Create table tbl_KeyValue
    value char(3) NULL,
    keys int NULL
    Insert into tbl_Keyvalue values('A',1)
    Insert into tbl_Keyvalue values('B',2)
    Insert into tbl_Keyvalue values('C',3)
    Insert into tbl_Keyvalue values('D',4)
    Insert into tbl_Keyvalue values('E',5)
    Insert into tbl_Keyvalue values('F',6)
    Insert into tbl_Keyvalue values('G',7)
    Main Procedure:
    CREATE PROCEDURE DBO.SP_WRAPPD
    (PRODUCT1 VARCHAR(1000))
    AS
    BEGIN
    DECLARE @COMMA VARCHAR(2)
    SET @COMMA =','
    SELECT CODE FROM TBL_PRODUCT WHERE CHARINDEX(PRODUCT,@PRODUCT) >0
    END
    Second procedure:
    Create Procure sp_findIndexes(@value varchar(10))
    as
    begin
    Declare @keys int
    set @Keys =(select A.keys from tbl_keyvalue A where A.value=@value)
    Declare @Evenodd varchar(10)
    Declare @result int
    Exec @result =sp_EvenOdds @keys
    if @result=1
    set @EvenOdd ='Even'
    else
    set @EvenOdd='Odd'
    insert into ##EvenOddResultss select A.keys,B.Product,@evenodd as evenodd from tbl_product B
    inner join
    tbl_KeyValue A
    on A.Value=B.code and A.keys=@keys
    end
    Third Procedure:
    Create procedure sp_EvenOdds (@Key int)
    as
    begin
    if(@key%2=0)
    return(1)
    else
    return(0)
    end
    I am calling third procure from second,second from Main Procedure

  • Can I use an OLE DB Command Task to call a parameterized stored procedure, perform some data editing and pass variables back to the SSIS for handling?

    I am using a Data Flow and an OLE DB Source to read my staged 3rd party external data. I need to do various Lookups to try and determine if I can find the external person in our database...by SSN...By Name and DOB...etc...
    Now I need to do some more data verification based on the Lookup that is successful. Can I do those data edits against our SQL server application database by utilizing an OLE DB Command? Using a Stored Procedure or can I sue straight SQL to perform my edit
    against every staging row by using a parameter driven query? I'm thinking a Stored Procedure is the way to go here since I have multiple edits against the database. Can I pass back the result of those edits via a variable and then continue my SSIS Data Flow
    by analyzing the result of my Stored Procedure? And how would I do that.
    I am new to the SSIS game here so please be kind and as explicit as possible. If you know of any good web sites that walk through how to perform SQL server database edits against external data in SSIS or even a YouTube, please let me know.
    Thanks!

    Thanks for that...but can I do multiple edits in my Stored Procedure Vaibhav and pass back something that I can then utilize in my SSIS? For example...
    One and Only one Member Span...so I'd be doing a SELECT COUNT(*) based on my match criteria or handle the count accordingly in my Stored Procedure and passing something back via the OLE DB Command and handling it appropriately in SSIS
    Are there "Diabetes" claims...again probably by analyzing a SELECT COUNT(*)
    Am I expecting too much from the SSIS...should I be doing all of this in a Stored Procedure? I was hoping to use the SSIS GUI for everything but maybe that's just not possible. Rather use the Stored Procedure to analyze my stged data, edit accordingly, do
    data stores accordingly...especially the data anomalies...and then use the SSIS to control navigation
    Your thoughts........
    Could you maybe clarify the difference between an OLE DB Command on the Data Flow and the Execute SQL Task on the Control Flow...
    You can get return values from oledb comand if you want to pipeline.
    see this link for more details
    http://josef-richberg.squarespace.com/journal/2011/6/30/ssis-oledb-command-and-procedure-output-params.html
    The procedure should have an output parameter defined for that
    I belive if you've flexibility of using stored procedure you may be better off doing this in execute sql task in control flow. Calling sp in data flow will cause it to execute sp once for each row in dataset whereas in controlflow it will go for set based
    processing
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How to improve stored procedure performance?

    hi,
    Suppose I have a stored procedure which contains 30 insert/update statements. How do I know Stored Procedure is slowly running or don't have any performance issue? how to improve performance?
    Thanks in advance.
    Anujit Karmakar Sr. Software Engineer

    Stored Procedures Optimization Tips
    Use stored procedures instead of heavy-duty queries.
    This can reduce network traffic, because your client will send to server only stored procedure name (perhaps with some parameters) instead of large heavy-duty queries text. Stored procedures can be used to enhance security and conceal underlying data objects
    also. For example, you can give the users permission to execute the stored procedure to work with the restricted set of the columns and data.
    Include the SET NOCOUNT ON statement into your stored procedures to stop the message indicating the number of rows affected by a Transact-SQL statement.
    This can reduce network traffic, because your client will not receive the message indicating the number of rows affected by a Transact-SQL statement.
    Call stored procedure using its fully qualified name.
    The complete name of an object consists of four identifiers: the server name, database name, owner name, and object name. An object name that specifies all four parts is known as a fully qualified name. Using fully qualified names eliminates any confusion about
    which stored procedure you want to run and can boost performance because SQL Server has a better chance to reuse the stored procedures execution plans if they were executed using fully qualified names.
    Consider returning the integer value as an RETURN statement instead of an integer value as part of a recordset.
    The RETURN statement exits unconditionally from a stored procedure, so the statements following RETURN are not executed. Though the RETURN statement is generally used for error checking, you can use this statement to return an integer value for any other reason.
    Using RETURN statement can boost performance because SQL Server will not create a recordset.
    Don't use the prefix "sp_" in the stored procedure name if you need to create a stored procedure to run in a database other than the master database.
    The prefix "sp_" is used in the system stored procedures names. Microsoft does not recommend to use the prefix "sp_" in the user-created stored procedure name, because SQL Server always looks for a stored procedure beginning with "sp_"
    in the following order: the master database, the stored procedure based on the fully qualified name provided, the stored procedure using dbo as the owner, if one is not specified. So, when you have the stored procedure with the prefix "sp_" in the
    database other than master, the master database is always checked first, and if the user-created stored procedure has the same name as a system stored procedure, the user-created stored procedure will never be executed.
    Use the sp_executesql stored procedure instead of the EXECUTE statement.
    The sp_executesql stored procedure supports parameters. So, using the sp_executesql stored procedure instead of the EXECUTE statement improve readability of your code when there are many parameters are used. When you use the sp_executesql stored procedure to
    executes a Transact-SQL statements that will be reused many times, the SQL Server query optimizer will reuse the execution plan it generates for the first execution when the change in parameter values to the statement is the only variation.
    Use sp_executesql stored procedure instead of temporary stored procedures.
    Microsoft recommends to use the temporary stored procedures when connecting to earlier versions of SQL Server that do not support the reuse of execution plans. Applications connecting to SQL Server 7.0 or SQL Server 2000 should use the sp_executesql system
    stored procedure instead of temporary stored procedures to have a better chance to reuse the execution plans.
    If you have a very large stored procedure, try to break down this stored procedure into several sub-procedures, and call them from a controlling stored procedure.
    The stored procedure will be recompiled when any structural changes were made to a table or view referenced by the stored procedure (for example, ALTER TABLE statement), or when a large number of INSERTS, UPDATES or DELETES are made to a table referenced by
    a stored procedure. So, if you break down a very large stored procedure into several sub-procedures, you get chance that only a single sub-procedure will be recompiled, but other sub-procedures will not.
    Try to avoid using temporary tables inside your stored procedure.
    Using temporary tables inside stored procedure reduces the chance to reuse the execution plan.
    Try to avoid using DDL (Data Definition Language) statements inside your stored procedure.
    Using DDL statements inside stored procedure reduces the chance to reuse the execution plan.
    Add the WITH RECOMPILE option to the CREATE PROCEDURE statement if you know that your query will vary each time it is run from the stored procedure.
    The WITH RECOMPILE option prevents reusing the stored procedure execution plan, so SQL Server does not cache a plan for this procedure and the procedure is recompiled at run time. Using the WITH RECOMPILE option can boost performance if your query will vary
    each time it is run from the stored procedure because in this case the wrong execution plan will not be used.
    Use SQL Server Profiler to determine which stored procedures has been recompiled too often.
    To check the stored procedure has been recompiled, run SQL Server Profiler and choose to trace the event in the "Stored Procedures" category called "SP:Recompile". You can also trace the event "SP:StmtStarting" to see at what point
    in the procedure it is being recompiled. When you identify these stored procedures, you can take some correction actions to reduce or eliminate the excessive recompilations.
    http://www.mssqlcity.com/tips/stored_procedures_optimization.htm
    Ahsan Kabir Please remember to click Mark as Answer and Vote as Helpful on posts that help you. This can be beneficial to other community members reading the thread. http://www.aktechforum.blogspot.com/

  • Java stored procedures performance ....

    I am currently evaluating the use of Java stored procedures, but
    have so far found the performance to be incredibly poor. If I
    write a simple piece of SQL to insert 1 row to a 2 column table
    via a standalone JDBC application, the average elapsed time over
    5 runs is approx 24 milliseconds. If I move the same piece of
    code to a Java stored procedure, the elapsed time increases (on
    average) to 28 seconds ! Surely this shouldn't be the case; I
    had expected the performance to increase rather than plummet as
    is the case. The DBA team cannot find anything amiss in the
    database, & we are basically scratching our heads as to what the
    problem is. Is there something fundamental that needs to be done
    the database for a Java implementation ??
    ANY IDEAS ANYONE ???????
    nb: database ver 8.1.5, running on Solaris 5.7
    regards,
    Paul.
    null

    Try running long queries. In 8.1.6, we are concentrating more
    on increasing the performance of JDBC driver inside the server.
    Paul Jones (guest) wrote:
    : I am currently evaluating the use of Java stored procedures,
    but
    : have so far found the performance to be incredibly poor. If I
    : write a simple piece of SQL to insert 1 row to a 2 column table
    : via a standalone JDBC application, the average elapsed time
    over
    : 5 runs is approx 24 milliseconds. If I move the same piece of
    : code to a Java stored procedure, the elapsed time increases (on
    : average) to 28 seconds ! Surely this shouldn't be the case; I
    : had expected the performance to increase rather than plummet as
    : is the case. The DBA team cannot find anything amiss in the
    : database, & we are basically scratching our heads as to what
    the
    : problem is. Is there something fundamental that needs to be
    done
    : the database for a Java implementation ??
    : ANY IDEAS ANYONE ???????
    : nb: database ver 8.1.5, running on Solaris 5.7
    : regards,
    : Paul.
    Oracle Technology Network
    http://technet.oracle.com
    null

Maybe you are looking for

  • Is it possible to add a single file to the Favorites list in a finder window?

    I can add a folder, OK, but can't figure out how to add a single file to the favorites list. Is there a way?

  • How to create Button which size is calculated from its text ?

    I think JButton works like this: either in constructor or by setText() method the text is set and according the lenght, font and fontRendererContext preffered size is calculated before the layout manager ask for the prefferedSize for first time. I wa

  • MacBook not reading the data on my harddrive now?

    So I have a Lacie 80 gig harddrive that I have been able to read before but for some reason it won't now. It shows that there is data on there but it won't show the folders. It does read my WD Passport and it's contents. I have all of my 60 gigs of m

  • Question about DB_AUTO_COMMIT

    I ' m wondering what will happen ,when I don't use DB_AUTO_COMMIT when open env and db???will my data lost?

  • Changing a testplan

    I have added new testdocuments in transaction SOLAR02, and I want them to be vissible in the already existing testplan. When I go into change testplan in transaction STWB_2, I receive the message: You wish to change a test plan that was created on th