Stored Procedure Output Issue in Query Template

Hi,
We have written a stored procedure which returns 3 outputs which are of type CLOB. Whenever we call the procedure from query template it gives an error Wrong number or type of parameters. It seems that we need to pass some variables which are of type clob to the procedure while calling which we cannot do as per my knowledge in query template.
Even if we are able to get the output we will not be getting complete output since the out put values are of type CLOB.
Can you guide me how to achive this
Thanks,
Shalaka

Hi,
Sometime back i faced the similar problem. But I used oracle pipelined functions to achieve this....
The basic thing is it will break the chunk into records of length of 4000 chars and it will return in a table. And from other end you can loop and concatenate. Hope this helps....
create or replace FUNCTION FN_GEN_XML RETURN dashb_xml pipelined IS v_xml CLOB := NULL;
v_temp VARCHAR2(4000) := NULL;
v_counter NUMBER := 1;
BEGIN
  SELECT somefunction(0)
  INTO v_xml
  FROM dual;--v_xml here is clob type. here you might need to call your proc and get it into this variable.
  dbms_output.put_line ('length of v_xml is:' || length(v_xml));
  DBMS_OUTPUT.PUT_LINE('start of this function');
  LOOP
    v_temp := SUBSTR(v_xml,   v_counter,   4000);
    EXIT
  WHEN v_temp IS NULL;
  DBMS_OUTPUT.PUT_LINE(to_char(v_temp));
  pipe ROW(v_temp);
  v_counter := v_counter + 4000;
END LOOP;
RETURN;
END;
Regards,
Ravi Kumar

Similar Messages

  • Problem Calling MaxDB stored procedure with output from MII Query template

    Hi,
    I am using Max DB Database studio to write stored procedure, I am calling stored procedure from MII Query using CALL statement.
    Can anyone guide me how to pass output values of stored procedure.
    Examlpe::
    call ProcName('[Param.1]','[Param.2]','[Param.3]','[Param.4]','[Param.5]', :isSuccess, :Trace)
    In the above line of code I am not able to get the output values of stored procedure that is isSuccess and Trace values in Query template when executed. But same thing I get when executed in Database studio.
    How do I call with outputs for any stored procedure in MII.
    Any help would be appriciated.
    Thanks,
    Padma

    My call statement is like this
    call RESULTDATA_INSERT('[Param.1]','[Param.2]','[Param.3]', :isSuccess, :Trace)
    I am able to insert record in DB, But I am not getting output values in Query template.I have done this in Fixed Query, when I execute it throws me "Fatal error as Loaded content empty".
    I tried giving select below call but it dont work.
    Regards,
    Rao

  • How to move stored procedure output to file

    Hi All,
    Thanks in advance.
    Please let me know how to move the oracle stored procedure output to the flat file.
    By
    Pyarajan

    Hi Pyarajan,
    As David posted, in the Data Flow Task (DFT), you can add an OLE DB Source, and create a connection manager to connect to the Oracle server using the Microsoft OLE DB for Oracle provider. Then, in the OLE DB Source Editor, you can set the “Data access mode”
    to “SQL command” and input the query to execute your Oracle stored procedure. To export the data to a flat file, we need to add a Flat File Destination to the DFT.
    Besides, also note that you need to install the Oracle client on this server, and you may need to edit the tnsnames.ora and sqlnet.ora files to establish the connection to Oracle successfully.
    References:
    http://commerceserverguy.wordpress.com/2011/12/04/ssis-package-tutorial/ 
    http://sqlblog.com/blogs/jorg_klein/archive/2011/06/09/ssis-connect-to-oracle-on-a-64-bit-machine.aspx 
    Regards,
    Mike Yin
    TechNet Community Support

  • Calling a Stored Procedure with output parameters from Query Templates

    This is same problem which Shalaka Khandekar logged earlier. This new thread gives the complete description about our problem. Please go through this problem and suggest us a feasible solution.
    We encountered a problem while calling a stored procedure from MII Query Template as follows-
    1. Stored Procedure is defined in a package. Procedure takes the below inputs and outputs.
    a) Input1 - CLOB
    b) Input2 - CLOB
    c) Input3 - CLOB
    d) Output1 - CLOB
    e) Output2 - CLOB
    f) Output3 - Varchar2
    2. There are two ways to get the output back.
    a) Using a Stored Procedure by declaring necessary OUT parameters.
    b) Using a Function which returns a single value.
    3. Consider we are using method 2-a. To call a Stored Procedure with OUT parameters from the Query Template we need to declare variables of
    corresponding types and pass them to the Stored Procedure along with the necessary input parameters.
    4. This method is not a solution to get output because we cannot declare variables of some type(CLOB, Varchar2) in Query Template.
    5. Even though we are successful (step 4) in declaring the OUT variables in Query Template and passed it successfully to the procedure, but our procedure contains outputs which are of type CLOB. It means we are going to get data which is more than VARCHAR2 length which query template cannot return(Limit is 32767
    characters)
    6. So the method 2-a is ruled out.
    7. Now consider method 2-b. Function returns only one value, but we have 3 different OUT values. Assume that we have appended them using a separator. This value is going to be more than 32767 characters which is again a problem with the query template(refer to point 5). So option 2-b is also ruled out.
    Apart from above mentioned methods there is a work around. It is to create a temporary table in the database with above 3 OUT parameters along with a session specific column. We insert the output which we got from the procedure to the temporary table and use it further. As soon the usage of the data is completed we delete the current session specific data. So indirectly we call the table as a Session Table. This solution increases unnecessary load on the database.
    Thanks in Advance.
    Rajesh

    Rajesh,
    please check if this following proposal could serve you.
    Define the Query with mode FixedQueryWithOutput. In the package define a ref cursor as IN OUT parameter. To get your 3 values back, open the cursor in your procedure like "Select val1, val2, val3 from dual". Then the values should get into your query.
    Here is an example how this could be defined.
    Package:
    type return_cur IS ref CURSOR;
    Procedure:
    PROCEDURE myProc(myReturnCur IN OUT return_cur) ...
    OPEN myReturnCur FOR SELECT val1, val2, val3  FROM dual;
    Query:
    DECLARE
      MYRETURNCUR myPackage.return_cur;
    BEGIN
      myPackage.myProc(
        MYRETURNCUR => ?
    END;
    Good luck.
    Michael

  • How to retrieve Stored Procedure Output Parameter?

    Hi,
    I'm using a stored procedure with MS SQL Server. The stored procedure creates the required table entries correctly. After executing the procedure i free the resulting recordset reference and am able to retrieve the return value of the stored procedure. However,
    I am not able to retrieve the output parameters of the procedure. I am connected to the database using the MS OLE DB Provider for SQL Server. I tried using ODBC as well. Didn't work either. I know this issue has been addressed before, did anyone come up with a solution for this problem?
    Thanks in advance,
    Marco

    I can tell you what I do with LabSQL and a single output parameter. After I open the connection to the database, I execute a SQL statement that looks like this:
    declare @resultID int
    execute spInsUUTResult @SerialNumber = '999DEBUGXXX',
    @SequenceName = 'Sequence File2.seq',
    @CategoryID = 2,
    @TypeID = 1,
    @StartDateTime = '10-10-2003 13:42:45',
    @ExecutionTime = 3.5698713,
    @UUTStatus = 'Passed',
    @UserName = 'Dennis Knutson',
    @StationName = 'DENNIS-KNUTSON',
    @UUTResultID = @resultID OUTPUT
    This query result is the output parameter. I first debugged the call to the stored procedure in the SQL Server Query Analyzer and then just copied that straight into my LabVIEW code. You may be using something other than LabSQL but you should have a function t
    hat allows for raw SQL commands.

  • 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

  • SSRS - Stored procedure with Dynamic SQL Query

    Am calling stored procedure in SSRS report.  I have used Dynamic SQL query in stored procedure as I don't know the column name and column count.  And I have used like below at end of the stored procedure "select * from ##temptable".
    As I have used dynamic column, am not able to create report with this stored procedure.  Can someone help me out to resolve this issue.
    It will be highly appreciated if I get help. 
    Thanks

    I have tried everything.  But nothing has worked out. 
    If I get solution for below issue, it would be highly appreciated.
    "An error occurred during local report processing.
    The definition of the repport 'Main Report' is invalid.
    The report defintion is not valid.  Details: The report definition has an invalid target namespace 'http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition' which cannot be upgraded.
    Thanks
    Hello,
    I would suggest you post the complete error message to us for further investigation, if you preview the report before you deploy you may get a more detailed error that will help diagnose the source of the problem.
    This issue is more related to SQL Server Reporting Services, it's more appropriate to discuss it in the forum below:
    https://social.technet.microsoft.com/Forums/sqlserver/en-US/home?forum=sqlreportingservices
    Don't forget to elaborate your issue with more detail.
    For the manual column, it might be the calculated field in SSRS. Here is the article for your reference, please see:
    http://technet.microsoft.com/en-us/library/dd239322(v=sql.110).aspx
    Regards,
    Elvis Long
    TechNet Community Support

  • Design Question::Instantiating Object from Stored Procedure Output

    Hi All,
    I am confused with approaching this design issue. I called a Stored Procedure, and the output from the Stored Procedure is a REF CURSOR. The size of the REF CURSOR can be large.
    My Question is, is it a good idea to pass the values from the REF CURSOR to a class constructor, there by instantiating an object of that type. lets say
    //rset is of type ((OracleCallableStatement)callableStatement).getCursor(5);
    //rset is not ResultType
    while (rset.next()){
    new ClassXYZ(var1, var2, var3);
    /*var1, var2, var3 would be rset.getObject(1),rset.getObject(2),rset.getObject(3)
    Class XYZ does some business logic
    }Other things:
    1) Will the JVM hold up assuming good enough JVM mem size, while creating objects for the range 100 thousands?
    2) I do not know the cursor size. It can change randomly from business perspective. And, it would be in the range of 100 thousands
    I was thinking, If I can "police" the call to the Class XYZ in case of large data. May be I am totally off the best solution. Any light on the best way to approach will be great.
    Anyhow, this would be a standalone java application. Just in case if people are trying to suggest/recommend DAO etc.,
    Thank you,
    VJ

    You can use ConvertTo-Html:
    http://ss64.com/ps/convertto-html.html
    Here's an example:
    http://social.technet.microsoft.com/Forums/scriptcenter/en-US/5cb016d3-e2fb-43e7-9c01-10b6878056e4/formattable-lost-in-email
    Don't retire TechNet! -
    (Don't give up yet - 13,085+ strong and growing)

  • FOR XML will not run in stored procedure but will in Query

    The following is the Query and stored procedure for a XML export.  The query runs find and returns a clickable link. The stored procedure does not.
    Stored Procedure
    USE [db]
    declare @XmlOutput1 xml
    set @XmlOutput1 =
    (SELECT incident_num,
    unit_id, unit_status_datetime,
    unit_status_remarks
    FROM unit_status_hist
    where convert(varchar,unit_status_datetime,102)
    =
    convert(varchar,getdate(),102)
    FOR XML
    RAW)
    select @XmlOutput1
    Query:
    use db
    SELECT incident_num, unit_id,
    unit_status_datetime,  unit_status_remarks
    FROM unit_status_hist
    WHERE  convert(varchar,unit_status_datetime,102)
    =
    convert(varchar,getdate(),102)
    for XML
    auto, Elements
    Any help would be greatly appreciated.  Thank you.

    The following is the Query and stored procedure for a XML export.  The query runs find and returns a clickable link. The stored procedure does not.
    Stored Procedure
    USE [db]
    declare @XmlOutput1 xml
    set @XmlOutput1 =
    (SELECT incident_num,
    unit_id, unit_status_datetime,
    unit_status_remarks
    FROM unit_status_hist
    where convert(varchar,unit_status_datetime,102)
    =
    convert(varchar,getdate(),102)
    FOR XML
    RAW)
    select @XmlOutput1
    Query:
    use db
    SELECT incident_num, unit_id,
    unit_status_datetime,  unit_status_remarks
    FROM unit_status_hist
    WHERE  convert(varchar,unit_status_datetime,102)
    =
    convert(varchar,getdate(),102)
    for XML
    auto, Elements
    Any help would be greatly appreciated.  Thank you.
    I cant see any stored procedure here
    both of the code posted are queries only
    also clickable link will come in only SSMS query window. Are you trying to execute this from some application?
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Using stored procedure vs ad hoc query

    Dears,
    I am using Visual Studio 2003 with Oracle. It is said that we can performance benefits by using SPs. Definitly it will have some drawbacks as well. Some peoples says we should write everything in SP even simple select/insert. Others beleive using SP only when lengthy manipulation is reqd. So i want i know when one should use SPs.
    Thanx in Advance,

    I know Sql Server supportes parameterized queries,
    but I was under the impression that in doing so the
    query is "hard-parsed" each time the request is sent,
    where as Oracle will cache the execution plan.Actually SQL has some pretty sophisiticated mechanisms for storing and reusing query plans even when the clients send nothing but ad-hoc SQL.
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsql7/html/sqlquerproc.asp
    And so SQL doesn't really suffer as badly from un-parameritized queries as Oracle.
    >
    Where I am still hung up, when porting to Oracle from
    Sql Server, is when multiple rows are returned (using
    .net as the application and presentation layers). I
    have read that the oracle sp must return a ref
    cursor, which is a poor performer. Ref cursors are fine. Their performance is good, but that doesn't really even matter since they are the only game in town. If you are porting SQL Server stored procedures, then you probably can't live without return result sets from stored procedures. To do that in Oracle, you are going to have to use ref cursors. It'll cost you some soft parses, but it's really a small price. Really.
    >
    For methods that create or update data (no result,
    except maybe an output variable in some cases), or
    return a single row (such as fetching by rowID), use
    a stored proc.
    For methods that return multiple rows, use a select
    statement with binding.I think you're a bit too woried about performance. If you have a good logical design, and take some care with the physical design (you have a ton of choices in Oracle you didn't have in SQL Server), and use either parameritized queries or stored procedures your performance will be 99% of what it could be.
    For everything else, make your code as simple and easy to live with as possible.
    David

  • 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.

  • Can we get data return from stored procedure in a select query ?

    Hello,
    Suppose i have a function GetSum(x,y) that returns sum of two numbers x and y .We can call this function from within a sql function like this :
    select GetSum(4,5) SUM from dual;But is this possible through a stored procedure ? i.e., can i call a stored procedure from within a select query like i have done in above code ?

    Hi,
    bootstrap wrote:
    Hello,
    Suppose i have a function GetSum(x,y) that returns sum of two numbers x and y .We can call this function from within a sql function like this :
    select GetSum(4,5) SUM from dual;But is this possible through a stored procedure ? i.e., can i call a stored procedure from within a select query like i have done in above code ?The short answer has already been given.
    Why can't you use a function?
    Suppose you could use a procedure. What results would you want to see from:
    SELECT  my_proc (4, 5)
    FROM    dual
    ;? Why?
    Explain what you want to do, and somebody will help you find a good way to do it.

  • Assigning stored procedure output value to java variable

    I have one stored procedure which is having ref cursor as the output parameter.
    How to assign refcursor value to my java variable?

    cstmt.registerOutParameter(1, OracleTypes.CURSOR);
    cstmt.execute()
    ResultSet rs = (ResultSet)cstmt.getObject(1);
    ==
    Ashok

  • Stored procedure OUTPUT VARCHAR2 value truncated using 12c client on Server 2012

    Questions:
    1) Is there a version of Oracle Client 11g which runs on Server 2012? My 11.2.0.0, when the installer begins, says my Server 2012 (8GB mem, 80 GB drive) does not meet the minimum requirements and I should not install it. This same installer worked on Server 2008.
    2) Have you seen the following behavior from Oracle client 12c? Are there any patches?
    When I was unable to find a version of Oracle 11g client for Windows Server 2012, I downloaded Oracle 12c. We have a few stored procedures, when invoked from a Windows Server 2008 with an 11g client work. However, when running that some code on a Windows Server 2012 machine does not work. I have certain stored procedures with an OUTPUT parameter when executed on 2012 has the values truncated.
    For instance:
    Output parameter is set to return "SUCCESS", but was is received is "SUC"
    Ouput parameter is set to return "AllSet", but it returns "All"
    Output parameter is set to cast a NUMBER to a VARCHAR2 and the value is a 5 digit number, but only the first two digits are returned. Ex: "83976", but only "83" appears.
    The above takes place when run from Server 2012, but works fine from Server 2008 and Win 7.

    Questions:
    1) Is there a version of Oracle Client 11g which runs on Server 2012? My 11.2.0.0, when the installer begins, says my Server 2012 (8GB mem, 80 GB drive) does not meet the minimum requirements and I should not install it. This same installer worked on Server 2008.
    2) Have you seen the following behavior from Oracle client 12c? Are there any patches?
    When I was unable to find a version of Oracle 11g client for Windows Server 2012, I downloaded Oracle 12c. We have a few stored procedures, when invoked from a Windows Server 2008 with an 11g client work. However, when running that some code on a Windows Server 2012 machine does not work. I have certain stored procedures with an OUTPUT parameter when executed on 2012 has the values truncated.
    For instance:
    Output parameter is set to return "SUCCESS", but was is received is "SUC"
    Ouput parameter is set to return "AllSet", but it returns "All"
    Output parameter is set to cast a NUMBER to a VARCHAR2 and the value is a 5 digit number, but only the first two digits are returned. Ex: "83976", but only "83" appears.
    The above takes place when run from Server 2012, but works fine from Server 2008 and Win 7.

  • Stored Procedure Command issues in CS3

    I've been having a problem using some stored procedures in
    CS3 which had previously worked with no issue in 8.0.2. I'm running
    CS3 on a Mac for ASP & SQL Server 2000.
    The input parameters for the stored procedure are...
    Fieldname: CategoryID (int) length: 4
    Fieldname: Men (bit) length: 1
    Fieldname: Women(bit) length:1
    I have no problem using the Command function to call this
    stored procedure in DW 8.0.2, but in CS3, while I am able to TEST
    the recordset successfully within the Command dialog, when I press
    OK and then attempt to view the field list in the Bindings panel, I
    get this error...
    [Microsoft][ODBC SQL Server Driver][SQL Server]Procedure
    'spCategoryProduct' expects parameter '@Men', which was not
    supplied.
    When I open up the command settings dialog again, Default
    Values and the Runtime Values I entered for the Men and Women bit
    parameter are blank. The only Default Value and Runtime Value
    retained is for the field CategoryID.
    CS3 is able to call other stored procedures which do not
    contain a Bit field type without issue, so I'm curious if this is
    the culprit.
    I have DW8.0.2 still installed on the same system, and have
    been able to call this stored procedure in this older version,
    without any problems.
    Please help!

    Holy thread-resurrection Batman!
    Please open a new dicussion after reading the bi4.0 data access guide: http://help.sap.com/businessobject/product_guides/boexir4/en/xi4sp5_data_acs_en.pdf
    Also, please specify which SP and Patch you are using.
    Regards,
    H

Maybe you are looking for

  • Is it possible to get the workspace which has been purged already?

    Hi All, I have created some sample applications in a workspace name " NEWAPP".I was unable to access the workspace for long time due to my higher studies.After long gap i was trying to log in with the credentials but i couldn't be able to access that

  • Unable to open a file in Application server

    This path exist in the Application server.         DR1/interfaces/Esker ORDHIST - This is the File name in whihc i need to save the data. I had specified the whole path as DR1/interfaces/Esker/ORDHIST I am trying to upload the data from the Internal

  • Transfer music between ipod and iphone

    I'm having trouble transfering my music from iPod Touch to my iPhone. How to do this?

  • Sdo web service errors

    Hi, I try to use a sdo webservice in an other project but this fails. I created a sdo webservice by creating a service interface in a bc4j application module. this works fine I can deploy it to a oc4j container and test the web service operation find

  • Delaying start of movie

    I have a short movie that I want to load normally, without the play controller being visible, and then for it so start to play automatically, but not until about 5/10 sec or so after the page has opened. Can't seem to find a neat way of doing it. Any