Improve the performance in stored procedure using sql server 2008 - esp where clause in very big table - Urgent

Hi,
I am looking for inputs in tuning stored procedure using sql server 2008. l am new to performance tuning in sql,plsql and oracle. currently facing issue in stored procedure - need to increase the performance by code optmization/filtering the records using where clause in larger table., the requirement is Stored procedure generate Audit Report which is accessed by approx. 10 Admin Users typically 2-3 times a day by each Admin users.
It has got CTE ( common table expression ) which is referred 2  time within SP. This CTE is very big and fetches records from several tables without where clause. This causes several records to be fetched from DB and then needed processing. This stored procedure is running in pre prod server which has 6gb of memory and built on virtual server and the same proc ran good in prod server which has 64gb of ram with physical server (40sec). and the execution time in pre prod is 1min 9seconds which needs to be reduced upto 10secs or so will be the solution. and also the exec time differs from time to time. sometimes it is 50sec and sometimes 1min 9seconds..
Pl provide what is the best option/practise to use where clause to filter the records and tool to be used to tune the procedure like execution plan, sql profiler?? I am using toad for sqlserver 5.7. Here I see execution plan tab available while running the SP. but when i run it throws an error. Pl help and provide inputs.
Thanks,
Viji

You've asked a SQL Server question in an Oracle forum.  I'm expecting that this will get locked momentarily when a moderator drops by.
Microsoft has its own forums for SQL Server, you'll have more luck over there.  When you do go there, however, you'll almost certainly get more help if you can pare down the problem (or at least better explain what your code is doing).  Very few people want to read hundreds of lines of code, guess what's it's supposed to do, guess what is slow, and then guess at how to improve things.  Posting query plans, the results of profiling, cutting out any code that is unnecessary to the performance problem, etc. will get you much better answers.
Justin

Similar Messages

  • How to Migrate Stored procedure on Sql server 2008 to Oracle Database

    Guys, I need help vey badly as I am new in this field.
    Problem is that, I have to migrate stored procedure on Sql server 2008 to oracle Oracle database:
    Whole scenario--
    1. Sql Server 2008 application on Windows server (source machine)
    2. I have to migrate 70 Stored Procedure
    3. To Oracle Database on Linux machine (Target machine)
    Any method (no problem)
    Please, help me or give me any reference as I don't know which keyword is differ in both database.
    Thanks in advance

    Hi,
      You could the free Oracle SQL*Developer to do this.
    There is information and a download link here -
    Oracle SQL Developer</title><meta name="Title" content="Oracle SQL Developer"><meta n…
    and information on using it for migrations here -
    http://www.oracle.com/technetwork/database/migration/index-084442.html
    You could use it in 2 ways -
    1. Go through a migration but just pull the stored procedure code from the file created after you generate the SQL from the SQL*Server database
    2. Use the scratch editor accessed from -
    - Tools - Migration - Scratch Editor
    and paste the SQL*Server stored procedure code into the window and it will convert it to Oracle code. The tool is very good but may have problems if you have very complicated procedures that use SQL*Server specific utilities.
    Regards,
    Mike

  • Improving the performance of Stored Procedure

    need to improve the performance of this SP that is hitting two tables that holds about 24000 rowsUSE [trouble_database]
    GO
    SET ANSI_NULLS OFF
    GO
    SET QUOTED_IDENTIFIER OFF
    GO
    ALTER PROCEDURE [dbo].[the_trouble_StoredProcedure]
    @troubleMedicatiotrouble_durationl int
    as
    declare @trouble_refil table
    ( troubleMedicatiotrouble_durationl int,
    trouble_durationl int
    declare @nRefillDispense int
    if exists (select ml.lid from trouble_MedicaticDirectmd
    inner join trouble_Medicatication ml on ml.troubleMedicatiotrouble_durationl=md.lID
    where isnull(md.trouble_bRefillDisp,0)=1
    and ml.lID <>(Select MIN(lID) from trouble_Medicatication where troubleMedicatiotrouble_durationl=@troubleMedicatiotrouble_durationl)
    begin
    select @nRefillDispense = isnull(nRefillDispense,9) from trouble_MedicaticDirect where lID=@troubleMedicatiotrouble_durationl
    insert @trouble_refil (trouble_durationl)
    select
    Case szIncrement
    when 'Day(s)' then isnull(trouble_durationl,0)
    when 'Week(s)' then isnull(trouble_durationl,0) * 7
    when 'Month(s)' then isnull(trouble_durationl,0) * 30
    when 'Year(s)' then isnull(trouble_durationl,0) * 365
    else 0
    end as trouble_durationl
    from
    trouble_Medicatication where
    troubleMedicatiotrouble_durationl=@troubleMedicatiotrouble_durationl
    and lID<>(Select min(lID) from trouble_Medicatication where troubleMedicatiotrouble_durationl=@troubleMedicatiotrouble_durationl)
    select @nRefillDispense as nRefillDispense, sum(trouble_durationl)as trouble_durationl from @trouble_refil
    end
    else
    select 0 as nRefillDispense,0 as trouble_durationl
    k

    you can use Execution plain
    http://stackoverflow.com/questions/7359702/how-do-i-obtain-a-query-execution-plan
    and add index.
    Index according to the fields you ask queries can improve performance greatly larger!
    You can use the statistics for building indexes:
    http://www.mssqltips.com/sqlservertip/2979/querying-sql-server-index-statistics/
    Tzuri Ben Ezra | My Certifications:
    CompTIA A+ ,Microsoft MCP, MCTS, MCSA, MCITP |
    FaceBook: Tzuri FaceBook | vCard:
    Tzuri vCard | 
    Microsoft ID:
    Microsoft Transcript 
     |

  • Creation of System Stored Procedure in SQL Server 2012 & SQL Server 2012 R2.

    Hi all,
    I am stuck at a point I am looking for a system stored procedure named 'sp_dboption' in SQL Server 2012  & R2 but could not find.
    Searched for it on the net and found that, this stored procedure 'sp_dboption' is now obsolete. So I tried to copy the content of 'sp_dboption' stored procedure from SQL Server 2008 R2 and create new system stored procedure with this name 'sp_dboption' in
    SQL Server 2012 but was unable to create the system stored procedure.
    Can you guys please tell me how to create system stored procedure in SQL Server 2012 & SQL Server 2012 R2. The reason of why I want to achieve this is because I have used 'sp_dboption' system stored procedure  in my application to create a database.
    As 'sp_dbotion' stored procedure is present in SQL Server 2008 R2 I am able to create the database in SQL server 2008 R2 but not in SQL server 2012.
    Can you please guide me how to create system stored procedure. I am out of luck.
    Please assist me, thanks & looking for help at the earliest. Hope someone will come to the fore and help me.

    Hi Vishwajeet,
    If you tried to create any object in the sys schema, you will get the error below.
    The specified schema name "sys" either does not exist or you do not have permission to use it.
    So I am afraid creating any object in sys schema is not supported by SQL Server. Here is a similar link for your reference.
    How to create table in SYS schema in SQL Server?
    Though sp_dboption is not in SQL Server 2012, does creating a user-defined one with the same content in 2008 make any difference in your business? You just need to specify the fully qualified name dbname.dbo.sp_dboption.
    If you are still interested in creating a system sp_dboption, you can register it with the
    sp_ms_marksystemobject.
    See
    Creating Your Own SQL Server System Stored Procedures.
    Eric Zhang
    TechNet Community Support

  • Debugging stored procedure in SQL Server 2012

    Hi,
    Please I need your help.
    I used to debug stored procedures in SQL server 2008, 2008 R2. I'm debugging the stored procedure using SQL Server management studio. I just create a break point then I click on the debug button
    and start debugging without any problems.
    I'm talking about my local machine which I have administrator privileges on the machine. My account in the administrators group and I'm assigned in the sysadmin role in SQL server but I couldn't
    debug the stored procedure. When I create a break point and try to debug the stored procedure I'm getting a popup screen saying "To continue debugging, the firewall needs to be configured. Configuring the firewall requires privileges."
    I tried to figure out the issue but unfortunately until now I'm not able to resolve it.
    Thanks. 

    The problem resolved with help of Microsoft support but it was really strange situation.
    First, the following is my environment.
    OS is Windows 8 Pro
    SQL Server 2012
    I did try everything firewall, Anti-Virus and other thing as well. I usually type (local) on the server name TextBox. I did close my Anti-Virus program, turn off windows firewall and run SQL server as administrator but I’m still
    unable to debug.
    I just do one thing and one thing only, changed the (local) on the server name TextBox to the actual server name and everything work fine. I did try that with everything close/open my Anti-Virus program, turn
    off/one windows firewall and still work fine, and I was able to debug any T-SQL in SQL server 2012 but run it as administrator.
    Anyway, I’m happy to back on the road again.
    Thank you every single one of you who try his best to help.
    Cheers.

  • One of the Column returned as NULL from SQL Server 2008

    Hi,
    I have written a stored procedure in SQL server 2008. The procedure reads data into a temporary table @MeterWiseConsumptionBetwDates as shown
    SELECT @sqlstatement =     'SELECT '''@MeterName''', CAST ( MAX('@Meterfield') AS FLOAT )-CAST ( MIN('@Meterfield') AS FLOAT )
                                  FROM KWH
                                  WHERE     KWH.timestamp BETWEEN @StDate AND @EndDate'
    INSERT INTO @MeterWiseConsumptionBetwDates(MeterName,Consumption)
    EXEC sp_executesql @sqlstatement, N'@StDate datetime, @EndDate datetime', @StDate, @EndDate
    Now when I execute the stored procedure in SQL Server Management Studio it returns all the columns from the table @MeterWiseConsumptionBetwDates, but when I execute the procedure in MII it returns the values in the Consumption column as null. The MeterName column is returned correctly in both the cases.
    Please help.
    Thanks

    Glad to hear that it is working.  You should be able to use
    execute <proc name> '[SD]'
    [SD] and [ED]
    are the query date tokens, so whatever you have assigned on the Date Range tab will be passed to the query.
    Jamie
    Edited by: Jamie Cawley on May 9, 2011 9:40 AM

  • Does Oracle have Extended Stored Procedure like SQL Server and Sybase?

    Hi, i am new to Oracle. I want to know if...
    Does Oracle have Extended Stored Procedure like SQL Server and Sybase?
    If it does not have, then how can i call outside program written in C or JAVA from the Database stored procedure or trigger?

    refer to this link on external procedures
    http://download-west.oracle.com/docs/cd/A87860_01/doc/server.817/a76956/manproc.htm#11064

  • I have enabled both the traces 1204 and 1222 in sql server 2008 but not able to capture deadlocks

    In Application error:
    2014-09-06 12:04:10,140 ERROR [org.apache.catalina.core.ContainerBase] Servlet.service() for servlet DoMethod threw exception
    javax.servlet.ServletException: java.lang.Exception: [ErrorCode] 0010 [ServerError] [DM_SESSION_E_DEADLOCK]error:  "Operation failed due to DBMS Deadlock error." 
    And
    I have enabled both the traces 1204 and 1222 in sql server 2008 but still I am not getting any deadlock in sql server logs.
    Thanks

    Thanks Shanky may be u believe or not but right now I am in a migration of 4 lakh documents in documentum on Production site.
    and the process from documentum is halting due to this error but I am not able to get any deadlock in the sql server while the deadlock error is coming in documentum:
    [ Date ] 2014-09-06 17:54:48,192 [ Priority ] INFO [ Text 3 ] [STDOUT] 17:54:48,192 ERROR [http-0.0.0.0-9080-3] com.bureauveritas.documentum.commons.method.SystemSessionMethod - ERROR 100: problem occured when connecting repository! DfServiceException::
    THREAD: http-0.0.0.0-9080-3; MSG: [DM_SESSION_E_DEADLOCK]error: "Operation failed due to DBMS Deadlock error."; ERRORCODE: 100; NEXT: null at com.documentum.fc.client.impl.connection.docbase.netwise.NetwiseDocbaseRpcClient.checkForDeadlock(NetwiseDocbaseRpcClient.java:276)
    at com.documentum.fc.client.impl.connection.docbase.netwise.NetwiseDocbaseRpcClient.applyForObject(NetwiseDocbaseRpcClient.java:647) at com.documentum.fc.client.impl.connection.docbase.DocbaseConnection$8.evaluate(DocbaseConnection.java:1292) at com.documentum.fc.client.impl.connection.docbase.DocbaseConnection.evaluateRpc(DocbaseConnection.java:1055)
    at com.documentum.fc.client.impl.connection.docbase.DocbaseConnection.applyForObject(DocbaseConnection.java:1284) at com.documentum.fc.client.impl.docbase.DocbaseApi.authenticateUser(DocbaseApi.java:1701) at com.documentum.fc.client.impl.connection.docbase.DocbaseConnection.authenticate(DocbaseConnection.java:418)
    at com.documentum.fc.client.impl.connection.docbase.DocbaseConnection.open(DocbaseConnection.java:128) at com.documentum.fc.client.impl.connection.docbase.DocbaseConnection.<init>(DocbaseConnection.java:97) at com.documentum.fc.client.impl.connection.docbase.DocbaseConnection.<init>(DocbaseConnection.java:60)
    at com.documentum.fc.client.impl.connection.docbase.DocbaseConnectionFactory.newDocbaseConnection(DocbaseConnectionFactory.java:26) at com.documentum.fc.client.impl.connection.docbase.DocbaseConnectionManager.getDocbaseConnection(DocbaseConnectionManager.java:83)
    at com.documentum.fc.client.impl.session.SessionFactory.newSession(SessionFactory.java:29) at com.documentum.fc.client.impl.session.PrincipalAwareSessionFactory.newSession(PrincipalAwareSessionFactory.java:35) at com.documentum.fc.client.impl.session.PooledSessionFactory.newSession(PooledSessionFactory.java:47)
    at com.documentum.fc.client.impl.session.SessionManager.getSessionFromFactory(SessionManager.java:111) at com.documentum.fc.client.impl.session.SessionManager.newSession(SessionManager.java:64) at com.documentum.fc.client.impl.session.SessionManager.getSession(SessionManager.java:168)
    at com.bureauveritas.documentum.commons.method.SystemSessionMethod.execute(Unknown Source) at com.documentum.mthdservlet.DfMethodRunner.runIt(Unknown Source) at com.documentum.mthdservlet.AMethodRunner.runAndReturnStatus(Unknown Source) at com.documentum.mthdservlet.DoMethod.invokeMethod(Unknown
    Source) at com.documentum.mthdservlet.DoMethod.doPost(Unknown Source) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:173)
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182) at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104) at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:619) (Log Path:SID CER > vmsfrndc01docpp > JMS_Log > server ,Host: vmsfrndc01docpp ,Apps: [SID CER, SID IVS])</init></init>
    Thanks

  • How to find the list of unused stored procedures in SQL Server 2005?

    Hi,
    I need to find out the list of stored procedures which are not in use.
    I found there is something called "sys.dm_exec_procedure_stats " for SQL server 2008.
    Can you please suggest your ides here to do the same job for SQL server 2005.
    Many Thanks.

    In SQL 2005 there is, sort of. This is query lists the last execution
    time for all SQL modules in a database:
       SELECT object_name(m.object_id), MAX(qs.last_execution_time)
       FROM   sys.sql_modules m
       LEFT   JOIN (sys.dm_exec_query_stats qs
                    CROSS APPLY sys.dm_exec_sql_text (qs.sql_handle) st) 
              ON m.object_id = st.objectid
             AND st.dbid = db_id()
       GROUP  BY object_name(m.object_id)
    But there are tons of caveats. The starting point of this query is
    the dynamic management view dm_exec_query_stats, and the contents is
    per *query plan*. If a stored procedure contains several queries, 
    there are more than one entry for the procedure in dm_exec_query_stats.
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Help to improve the performance of a procedure.

    Hello everybody,
    First to introduce myself. My name is Ivan and I recently started learning SQL and PL/SQL. So don't go hard on me. :)
    Now let's jump to the problem. What we have there is a table (big one, but we'll need only a few fields) with some information about calls. It is called table1. There is also another one, absolutely the same structure, which is empty and we have to transfer the records from the first one.
    The shorter calls (less than 30 minutes) have segmentID = 'C1'.
    The longer calls (more than 30 minutes) are recorded as more than one record (1 for every 30 minutes). The first record (first 30 minutes of the call) has segmentID = 'C21'. It is the first so we have only one of these for every different call. Then we have the next (middle) parts of the call, which have segmentID = 'C22'. We can have more than 1 middle part and again the maximum minutes in each is 30 minutes. Then we have the last part (again max 30 minutes) with segmentID = 'C23'. As with the first one we can have only one last part.
    So far, so good. Now we need to insert these call records into the second table. The C1 are easy - one record = one call. But the partial ones we need to combine so they become one whole call. This means that we have to take one of the first parts (C21), find if there is a middle part (C22) with the same calling/called numbers and with 30 minutes difference in date/time, then search again if there is another C22 and so on. And last we have to search for the last part of the call (C23). In the course of these searches we sum the duration of each part so we can have the duration of the whole call at the end. Then we are ready to insert it in the new table as a single record, just with new duration.
    But here comes the problem with my code... The table has A LOT of records and this solution, despite the fact that it works (at least in the tests I've made so far), it's REALLY slow.
    As I said I'm new to PL/SQL and I know that this solution is really newbish, but I can't find another way of doing this.
    So I decided to come here and ask you for some tips on how to improve the performance of this.
    I think you are getting confused already, so I'm just going to put some comments in the code.
    I know it's not a procedure as it stands now, but it will be once I create a better code. I don't think it matters for now.
    DECLARE
    CURSOR cur_c21 IS
        select * from table1
        where segmentID = 'C21'
        order by start_date_of_call;     // in start_date_of_call is located the beginning of a specific part of the call. It's date format.
    CURSOR cur_c22 IS
        select * from table1
        where segmentID = 'C22'
        order by start_date_of_call;
    CURSOR cur_c22_2 IS
        select * from table1
        where segmentID = 'C22'
        order by start_date_of_call;  
    cursor cur_c23 is
        select * from table1
        where segmentID = 'C23'
        order by start_date_of_call;
    v_temp_rec_c22 cur_c22%ROWTYPE;
    v_dur table1.duration%TYPE;           // using this for storage of the duration of the call. It's number.
    BEGIN
    insert into table2
    select * from table1 where segmentID = 'C1';     // inserting the calls which are less than 30 minutes long
    -- and here starts the mess
    FOR rec_c21 IN cur_c21 LOOP        // taking the first part of the call
       v_dur := rec_c21.duration;      // recording it's duration
       FOR rec_c22 IN cur_c22 LOOP     // starting to check if there is a middle part for the call
          IF rec_c22.callingnumber = rec_c21.callingnumber AND rec_c22.callednumber = rec_c21.callednumber AND 
            (rec_c22.start_date_of_call - rec_c21.start_date_of_call) = (1/48)                
    /* if the numbers are the same and the date difference is 30 minutes then we have a middle part and we start searching for the next middle. */
          THEN
             v_dur := v_dur + rec_c22.duration;     // updating the new duration
             v_temp_rec_c22:=rec_c22;               // recording the current record in another variable because I use it for the next check
             FOR rec_c22_2 in cur_c22_2 LOOP
                IF rec_c22_2.callingnumber = v_temp_rec_c22.callingnumber AND rec_c22_2.callednumber = v_temp_rec_c22.callednumber AND 
                  (rec_c22_2.start_date_of_call - v_temp_rec_c22.start_date_of_call) = (1/48)        
    /* logic is the same as before but comparing with the last value in v_temp...
    And because the data in the cursors is ordered by date in ascending order it's easy to search for another middle parts. */
                THEN
                   v_dur:=v_dur + rec_c22_2.duration;
                   v_temp_rec_c22:=rec_c22_2;
                END IF;
             END LOOP;                     
          END IF;
          EXIT WHEN rec_c22.callingnumber = rec_c21.callingnumber AND rec_c22.callednumber = rec_c21.callednumber AND 
                   (rec_c22.start_date_of_call - rec_c21.start_date_of_call) = (1/48);       
    /* exiting the loop if we have at least one middle part.
    (I couldn't find if there is a way to write this more clean, like exit when (the above if is true) */
       END LOOP;
       FOR rec_c23 IN cur_c23 LOOP             
          IF (rec_c23.callingnumber = rec_c21.callingnumber AND rec_c23.callednumber = rec_c21.callednumber AND
             (rec_c23.start_date_of_call - rec_c21.start_date_of_call) = (1/48)) OR v_dur != rec_c21.duration          
    /* we should always have one last part, so we need this check.
    If we don't have the "v_dur != rec_c21.duration" part it will execute the code inside only if we don't have middle parts
    (yes we can have these situations in calls longer than 30 and less than 60 minutes). */
          THEN
             v_dur:=v_dur + rec_c23.duration;
             rec_c21.duration:=v_dur;               // updating the duration
             rec_c21.segmentID :='C1';
             INSERT INTO table2 VALUES rec_c21;     // inserting the whole call in table2
          END IF;
          EXIT WHEN (rec_c23.callingnumber = rec_c21.callingnumber AND rec_c23.callednumber = rec_c21.callednumber AND
                    (rec_c23.start_date_of_call - rec_c21.start_date_of_call) = (1/48)) OR v_dur != rec_c21.duration;                 
                    // exit the loop when the last part has been found.
       END LOOP;
    END LOOP;
    END;I'm using Oracle 11g and version 1.5.5 of SQL Developer.
    It's my first post here so hope this is the right sub-forum.
    I tried to explain everything as deep as possible (sorry if it's too long) and I kinda think that the code got somehow hard to read with all these comments. If you want I can remove them.
    I know I'm still missing a lot of knowledge so every help is really appreciated.
    Thank you very much in advance!

    Atiel wrote:
    Thanks for the suggestion but the thing is that segmentID must stay the same for all. The data in this field is just to tell us if this is a record of complete call (C1) or a partial record of a call(C21, C22, C23). So in table2 as every record will be a complete call the segmentID must be C1 for all.Well that's not a problem. You just hard code 'C1' instead of applying the row number as I was doing:
    SQL> ed
    Wrote file afiedt.buf
      1  select 'C1' as segmentid
      2        ,start_date_of_call, duration, callingnumber, callednumber
      3  from (
      4        select distinct
      5               min(start_date_of_call) over (partition by callingnumber, callednumber) as start_date_of_call
      6              ,sum(duration) over (partition by callingnumber, callednumber) as duration
      7              ,callingnumber
      8              ,callednumber
      9        from table1
    10*      )
    SQL> /
    SEGMENTID  START_DATE_OF_CALL     DURATION CALLINGNUMBER   CALLEDNUMBER
    C1         11-MAY-2012 12:13:10 8020557824 1982032041      0631432831624
    C1         15-MAR-2012 09:07:26  269352960 5581790386      0113496771567
    C1         31-JUL-2012 23:20:23  134676480 4799842978      0813391427349
    Another thing is that, as I said above, the actual table has 120 fields. Do I have to list them all manually if I use something similar?If that's what you need, then yes you would have to list them. You only get data if you tell it you want it. ;)
    Of course if you are taking the start_date_of_call, callingnumber and callednumber as the 'key' to the record, then you could join the results of the above back to the original table1 and pull out the rest of the columns that way...
    SQL> select * from table1;
    SEGMENTID  START_DATE_OF_CALL     DURATION CALLINGNUMBER   CALLEDNUMBER          COL1       COL2       COL3
    C1         31-JUL-2012 23:20:23  134676480 4799842978      0813391427349          556         40       5.32
    C21        15-MAR-2012 09:07:26  134676480 5581790386      0113496771567          219        100      10.16
    C23        11-MAY-2012 09:37:26  134676480 5581790386      0113496771567          321         73       2.71
    C21        11-MAY-2012 12:13:10 3892379648 1982032041      0631432831624          959         80       2.87
    C22        11-MAY-2012 12:43:10 3892379648 1982032041      0631432831624          375         57       8.91
    C22        11-MAY-2012 13:13:10  117899264 1982032041      0631432831624          778         27       1.42
    C23        11-MAY-2012 13:43:10  117899264 1982032041      0631432831624          308         97       3.26
    7 rows selected.
    SQL> ed
    Wrote file afiedt.buf
      1  with t2 as (
      2  select 'C1' as segmentid
      3        ,start_date_of_call, duration, callingnumber, callednumber
      4  from (
      5        select distinct
      6               min(start_date_of_call) over (partition by callingnumber, callednumber) as start_date_of_call
      7              ,sum(duration) over (partition by callingnumber, callednumber) as duration
      8              ,callingnumber
      9              ,callednumber
    10        from table1
    11       )
    12  )
    13  --
    14  select t2.segmentid, t2.start_date_of_call, t2.duration, t2.callingnumber, t2.callednumber
    15        ,t1.col1, t1.col2, t1.col3
    16  from   t2
    17         join table1 t1 on (   t1.start_date_of_call = t2.start_date_of_call
    18                           and t1.callingnumber = t2.callingnumber
    19                           and t1.callednumber = t2.callednumber
    20*                          )
    SQL> /
    SEGMENTID  START_DATE_OF_CALL     DURATION CALLINGNUMBER   CALLEDNUMBER          COL1       COL2       COL3
    C1         11-MAY-2012 12:13:10 8020557824 1982032041      0631432831624          959         80       2.87
    C1         15-MAR-2012 09:07:26  269352960 5581790386      0113496771567          219        100      10.16
    C1         31-JUL-2012 23:20:23  134676480 4799842978      0813391427349          556         40       5.32
    SQL>Of course this is pulling back the additional columns for the record that matches the start_date_of_call for that calling/called number pair, so if the values differed from row to row within the calling/called number pair you may need to aggregate those (take the minimum/maximum etc. as required) as part of the first query. If the values are known to be the same across all records in the group then you can just pick them up from the join to the original table as I coded in the above example (only in my example the data was different across all rows).

  • Testing stored procedure using sql plus

    I'm attempt to create and test a stored procedure in sql plus.
    I enter:
    create procedure sp_getconfiguration(mygroup in char, myparameter in char, myvalue in out char) as begin select configvalue into myvalue from tblconfiguration where configgroup = mygroup and configparameter = myparameter; end;/
    I get a procedure created. response by when I type:
    variable myval char
    call sp_getconfiguration('Language','Enabled', myval);
    I get the following error:
    error at line 1:
    ora-06576: not a valid function or procedure name
    I can go into DBA studio and see the procedure listed and can compile it and it says "valid". I have tried granting execute permission to public and trying it again under sql plus and nothing seems to help.
    I'm also attempting to run this same procedure from VB and get an invalid column name error from there.
    Thanks for any help in advance.
    Lee

    Thanks for all your help. What I actually called product support and they helped me solve it. But what I found out is that if using oracle 8.1.# you have to invoke the stored procedure without the "call " in front of the procedure name. For instance.
    sp_getconfiguation()
    In version 9.# it appears that you use the call in front of the procedure. Dah! So if anyone else is having this problem. That is the solution. Thanks anyway.

  • Stored Procedure in SQL Server 2005

    Hi Friends,
    when i execute the stored procedure , i can get below error.
    Error processing request in sax parser: Error when executing statement for table/stored proc. 'XI_SP_KANLOGDATA_KLOGDATA' (structure 'Statement'): java.sql.SQLException: ERROR: Invalid XML document format for stored procedure: 'type="<SQL-type>"' attribute is missing for element 'table' (Setting a SQL-type (e.g. INTEGER, CHAR, DATE etc.) is mandatory !)
    My XML Message below format:
    <Statment>
    --<dbStmt action="EXECUTE">
      ---<table>storedprocedurename</table>
      ---<EMPNO isInput="true" type="char">0001</EMPNO>
      ---<EMPNAME isInput= "true type="char">Sateesh</EMPNAME>
      ---<ADDRESS isInput="true" type="char">Delhi</ADDRESS>
    --<dbStmt action="EXECUTE">
      ---<table>storedprocedurename</table>
      ---<EMPNO isInput="true" type="char">0002</EMPNO>
      ---<EMPNAME isInput= "true type="char">Sateesh1</EMPNAME>
      ---<ADDRESS isInput="true" type="char">Bangalore</ADDRESS>
    --<dbStmt action="EXECUTE">
      ---<table>storedprocedurename</table>
      ---<EMPNO isInput="true" type="char">0003</EMPNO>
      ---<EMPNAME isInput= "true type="char">Sateesh3</EMPNAME>
      ---<ADDRESS isInput="true" type="char">Hyderabad</ADDRESS>
    </Statement>

    Hi abishek,
    My scenario is basically JDBC(SQL Server)XIJDBC(ORACLE)(Synchronous)
    XI pick the date field from JDBC Sender and goes to ORACLE Database and selects records based upon the condition, and response back and put this data into JDBC(SQL Server),
    My process successfully upto receive the response from ORACLE system and after response mapping also successful.after that  response message is insert into SQL Server.
    In SQL server we have two tables,one DATA table and LOG table, If insert the data into DATA table successfully LOG table updated with DATE and STATUS field not successfully insert LOG table update with DATE and Error status field.
    So I impleted "stored procedure" in SQL side.
    Any way i solved that error.
    I am using below XML structure with out table field,i followed below blog.
    http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/9618. [original link is broken] [original link is broken] [original link is broken]
    My stored procedure name is: XI_SP_KDATA_KLOGDATA
    <?xml version="1.0" encoding="UTF-8" ?>
    - <ns0:MT_DB_SELECT_REQUEST_response xmlns:ns0="urn:pg-siemens-com:POCA0013:sample1">
    - <Statement_response>
    - <XI_SP_KDATA_KLOGDATA action="EXECUTE">
      <EMPNO type="CHAR">901064</EMPNO>
      <EMPNAME type="CHAR">Sateesh</EMPNAME>
      <ADDRESS type="CHAR">Hyderabad</ADDRESS>
      </XI_SP_KDATA_KLOGDATA>
    - <XI_SP_KDATA_KLOGDATA action="EXECUTE">
      <EMPNO type="CHAR">901000</EMPNO>
      <EMPNAME type="CHAR">Ashish</EMPNAME>
      <ADDRESS type="CHAR">Bangalore</ADDRESS>
      </XI_SP_KDATA_KLOGDATA>
      </Statement_response>
      </ns0:MT_DB_SELECT_REQUEST_response>
    But again i faced one error in Communication channel
    Message processing failed. Cause: com.sap.aii.af.ra.ms.api.RecoverableException: Error processing request in sax parser: Error when executing statement for table/stored proc. 'XI_SP_KDATA_KLOGDATA' (structure 'Statement_response'): com.microsoft.sqlserver.jdbc.SQLServerException: Procedure or function XI_SP_KANLOGDATA_KLOGDATA has too many arguments specified.
    My doubt is above error is Stored procedure error or XML Structure error?
    Don't hesitate to clarify me.
    Thank you.
    sateesh
    Edited by: sateesh kumar .N on Mar 4, 2010 11:58 AM
    Edited by: sateesh kumar .N on Mar 4, 2010 11:59 AM
    Edited by: sateesh kumar .N on Mar 4, 2010 12:00 PM

  • Missing Stored Procedure for SQL Server

    Hello,
    I'm trying to create the standard TestStand 4 schema for SQL Server. I get the following error when I run multiple numeric test cases:
    An error occurred calling 'LogResults' in 'ITSDBLog' of 'zNI TestStand Database Logging'
    An error occurred executing a statement.
    Schema: SQL Server Stored Proc (NI).
    Statement: MEAS_NUMERICLIMIT.
    Could not find stored procedure 'InsertStepMeasNumericLimit'.
    Description: Could not find stored procedure 'InsertStepMeasNumericLimit'.
    Number: -2147217900
    NativeError: 2812
    SQLState: 42000
    Reported by: Microsoft OLE DB Provider for SQL Server
    Source: TSDBLog
    -2147217900; User-defined error code.
    Step 'Log Results to Database' of sequence 'Log To Database' in 'Database.seq'
    My process for creating the database is to create a .sql file from the TestStand database configuration window. I have selected SQL Server Stored Procedure. I then build the database by running the script in the Execute SQL window of the Database viewer. I don't get any errors when creating the database or the stored procedures. I have noticed that a stored procedure, called InsertMeasNumericLimit does exist. When I rename this procedure to InsertStepMeasNumericLimit, the sequence with the multiple numeric executes without error, and my data is in the database.
    Now to my questions>
    1. Am I doing something wrong in my procedure to create the database schema, that would cause this?
    2. Have the NI schemas or DB calls in TS been changed since 3.5 and validated?
    3. Has anyone else run across this problem, and what others can I expect to encounter with the SQL server stored procedure schema?
    Thanks in advance for the help,
    BCE

    bce,
    1. What you are doing is correct. There is a bug with the SQL Server Stored Procedure. Apparently
    2. The schemas hasn't changed since 3.5? Were you able to go through the same process in TS 3.5 without running into this error?
    3. It looks like you have found the way to solve this problem. There are a few other step types that have similar error. Specifically the IVI steps. Before the bug is fixed, you can use validate to determines whether the statement and column information for the selected schema matches the tables and columns in the database. Alternatively, you may look at the file below to find out the correct spelling of the stored procedures.
    <TestStand 4.0>\Components\NI\Models\TestStandModels\Database\SQL Server Create Stored Proc Result Tables.sql
    Regards,
    Song Du
    Systems Software
    National Instruments R&D

  • Exception while calling stored procedure in SQL server

    Hi,
    I run into a problem while calling a proc in SQL server. I am using a database control to do so. The proc returns a integer. This is the first time I use SQL server. Any thoughts? Thanks in advance.
    My method call is:
    int createAccount(SQLParameter[] param)
    The sql is:
    {call espsiCompany(?, ?, ?)}
    The error is:
    java.lang.NullPointerException
    at com.bea.wlw.runtime.core.control.DatabaseControlImpl.getStatement_v2(DatabaseControlImpl.jcs:1885)
    at com.bea.wlw.runtime.core.control.DatabaseControlImpl.invoke(DatabaseControlImpl.jcs:2691)
    at com.bea.wlw.runtime.core.dispatcher.DispMethod.invoke(DispMethod.java:373)
    at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:423)
    at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:396)
    at com.bea.wlw.runtime.jcs.container.JcsProxy.invoke(JcsProxy.java:388)
    at services.OnyxDBControl.createAccount(OnyxDBControl.ctrl)
    at services.OnyxDBControlTest.createAccount(OnyxDBControlTest.jws:18)

    Hi. That's not the signature of the procedure. What I'd like to see is
    the SQL used to create the procedure, eg:
    create procedure myProc @foo int, @bar varchar(30) ....
    as
    begin
    end
    Jun Li wrote:
    Here you go. Thanks for your time.
    DECLARE @RC int
    DECLARE @iSiteId int
    DECLARE @iCompanyId int
    DECLARE @chLanguageCode char(4)
    DECLARE @vchAssignedId varchar(255)
    DECLARE @vchCompanyName varchar(255)
    DECLARE @vchAddress1 varchar(255)
    DECLARE @vchAddress2 varchar(255)
    DECLARE @vchAddress3 varchar(255)
    DECLARE @vchCity varchar(255)
    DECLARE @chRegionCode char(4)
    DECLARE @chCountryCode char(4)
    DECLARE @vchPostCode varchar(40)
    DECLARE @vchPhoneNumber varchar(40)
    DECLARE @vchEmailAddress varchar(255)
    DECLARE @vchURL varchar(255)
    DECLARE @iCompanyTypeCode int
    DECLARE @iCompanySubTypeCode int
    DECLARE @iFamilyId int
    DECLARE @iParentId int
    DECLARE @iPrimaryContactId int
    DECLARE @vchContactFirstName varchar(255)
    DECLARE @vchContactLastName varchar(255)
    DECLARE @iDivisionCode int
    DECLARE @iSICCode int
    DECLARE @iMarketSector int
    DECLARE @vchTaxId varchar(255)
    DECLARE @vchDunnsNumber varchar(255)
    DECLARE @iPhoneTypeId int
    DECLARE @iAddressTypeId int
    DECLARE @iSourceId int
    DECLARE @iStatusId int
    DECLARE @bValidAddress tinyint
    DECLARE @iAccessCode int
    DECLARE @bPrivate tinyint
    DECLARE @vchUser1 varchar(255)
    DECLARE @vchUser2 varchar(255)
    DECLARE @vchUser3 varchar(255)
    DECLARE @vchUser4 varchar(255)
    DECLARE @vchUser5 varchar(255)
    DECLARE @vchUser6 varchar(255)
    DECLARE @vchUser7 varchar(255)
    DECLARE @vchUser8 varchar(255)
    DECLARE @vchUser9 varchar(255)
    DECLARE @vchUser10 varchar(255)
    DECLARE @chInsertBy char(10)
    DECLARE @dtInsertDate datetime
    DECLARE @tiLockRecord tinyint
    DECLARE @tiRecordStatus tinyint
    DECLARE @tireturnType tinyint
    -- Set parameter values
    EXEC @RC = [ONYXPROD].[dbo].[espsiCompany] @iSiteId, @iCompanyId OUTPUT , @chLanguageCode, @vchAssignedId, @vchCompanyName, @vchAddress1, @vchAddress2, @vchAddress3, @vchCity, @chRegionCode, @chCountryCode, @vchPostCode, @vchPhoneNumber, @vchEmailAddress, @vchURL, @iCompanyTypeCode, @iCompanySubTypeCode, @iFamilyId, @iParentId, @iPrimaryContactId, @vchContactFirstName, @vchContactLastName, @iDivisionCode, @iSICCode, @iMarketSector, @vchTaxId, @vchDunnsNumber, @iPhoneTypeId, @iAddressTypeId, @iSourceId, @iStatusId, @bValidAddress, @iAccessCode, @bPrivate, @vchUser1, @vchUser2, @vchUser3, @vchUser4, @vchUser5, @vchUser6, @vchUser7, @vchUser8, @vchUser9, @vchUser10, @chInsertBy, @dtInsertDate, @tiLockRecord, @tiRecordStatus, @tireturnType

  • How to send PLAIN text email from sp_send_dbmail using SQL Server 2008 R2?

    I have configured Database Mail in SQL Server 2008 R2 (64) and it sends emails just fine. However the destination is recieving the body of thes message as Base 64 encoding.
    Snippet:
    EXEC msdb..sp_send_dbmail @profile_name='Outmail', @recipients = @recpts, @subject = @subj, @body_format = 'TEXT', @body=@body2;
    As you can see I set @body_format to TEXT, but it still sends Base 64. I need to send plain ASCII text. How can I change this?

    I am having this exact issue too.  I have a trigger that sends an email using a stored procedure.  The dbmail is sending the email using the Exchange 2010 server SMTP.  It does not login so the email is relayed as user = "Anonymous". 
    The SQL dbmail email header is showing the following:
    Content-Type: text/plain; charset="utf-8"
    Content-Transfer-Encoding: base64
    MIME-Version: 1.0
    X-MS-Exchange-Organization-AuthSource: MX01.domain.local
    X-MS-Exchange-Organization-AuthAs: Anonymous
    Here is the header if I send via Outlook profile using the legacy program I am trying to automate using SQL Server 2008R2:
    Content-Type: application/ms-tnef; name="winmail.dat"
    Content-Transfer-Encoding: binary
    MIME-Version: 1.0
    X-MS-Has-Attach:
    X-MS-Exchange-Organization-SCL: -1
    X-MS-TNEF-Correlator: <[email protected]>
    MIME-Version: 1.0
    X-MS-Exchange-Organization-AuthSource: MX01.domain.local
    X-MS-Exchange-Organization-AuthAs: Internal
    X-MS-Exchange-Organization-AuthMechanism: 03
    X-Originating-IP: [192.168.13.66]
    Any help would be greatly appreciated!

Maybe you are looking for

  • A1 -- Google Talk (chat) does not work for me

    I have not been able to get Google Talk to work on my A1 tablet since I got it.  The tablet does almost everything I want it to and I've been able to figure out and fix all the bugs so far except for Google Talk. When I try to start the app, I immedi

  • Disconnecting WEB SSL VPN client windows 7 to remote windows 7 virtual machine

    Good morning,           my problem, common to other colleagues who use Windows machines 7 Professional is this: I connect to WEB SSL VPN Cisco from Client Windows 7 Home Premium Explorer-9 to a virtual machine Windows 7 Professional using a specific

  • Sales order release strategy

    hello everybody. marketing person prepares the sales order and he enters some discount in the pricing procedure. the requirement is that a higher level person will first check if the discounting and other terms & conditions have been maintained corre

  • FPGA velocity estimation and VFD noise

    Hi, I'm using an NI FPGA (a 7411, I believe) with an RT unit and VFD to get very low lag, high resolution velocity estimation from a 3600 pulse/rev quadrature encoder (mounted on the VFD driven motor). When the VFD is off and I turn the encoder by ha

  • Gzip and compress slow on T6320

    So far testing has shown that gzip and compress run 2-3 times slower on the new blades as on the older V-440s. Mkfile, Tar, unzip, rm –rf, and Copy run at about the same speed. I have eliminated LDOMs, RAM, swap, and local hard drives as issues (by p