Getting two Outputs from same Stored Procedure

Last post 07-06-2009 4:24 PM by splitterside. 3 replies.

Sort Posts:

  • Getting two Outputs from same Stored Procedure

    07-06-2009, 2:32 PM
    • Member
      54 point Member
    • splitterside
    • Member since 06-26-2009, 11:12 AM
    • Posts 35

    Hey Everyone,

    I was wondering how I would get two output values from a single Stored Procedure using Linq. I need one to Bind with a DataView Control and another to set to an int variable.

    Here is the call of the SP currently:

    GVSearchResults.DataSource = db.search_FindFiles(
                                words[0],
                                (words.Length > 2 ? words[1] : " "),
                                (words.Length > 3 ? words[2] : " "),
                                (words.Length > 4 ? words[3] : " "),
                                (words.Length > 5 ? words[4] : " "),
                                (typeID != null ? typeID : "(-1)"),
                                (dateType != null ? dateType : "NetworkFileCreationDate"),
                                (dateOperator != null ? dateOperator : ">"),
                                (calDateSelected.SelectedDate.Date.ToShortDateString() == "1/1/0001"
                                    ? "1/1/1900" : calDateSelected.SelectedDate.Date.ToShortDateString()),
                                tableToSearch.LastTableFilled,
                                chkBxContent.Checked,
                                sortColumn,
                                sortDirection,
                                int.Parse(currentPage),
                                50
                                );
    GVSearchResults.DataBind();
    rowCount = ?
    		


    First Select Statement:

    SET @Sql= @Sql + '
    					SELECT st.NetworkFileName, nf.NetworkFileLocation, nft.TypeName, 
    					convert(varchar(50), nf.NetworkFileModifiedDate, 101) AS NetworkFileModifiedDate,
    					ROW_NUMBER() OVER(ORDER BY ' + @SortColumn + ') as ID
    					FROM #SearchTemp st
    					JOIN search_NetworkFiles' + ltrim(rtrim(str(@Table))) + ' nf on st.FileID = nf.FileID
    					JOIN search_NetworkFileTypes nft ON nf.TypeID = nft.TypeID
    					WHERE ' + str(@PageStart) + ' = 0 OR (ID between @FirstRec AND @LastRec)
    					ORDER BY  ' 
    				
    				SET @Sql = @Sql + CASE @SortDirection 
    					  WHEN 'DESC' THEN ' ID * -1  '
    					  WHEN 'desc' THEN  ' ID * -1 '
    					  ELSE ' ID ' 
    				END


    Second Select Statment:

    SET @Sql = @Sql + 'SELECT @TotalRows as TotalRows '


    Any Help would be greatly appreciated.

  • Re: Getting two Outputs from same Stored Procedure

    07-06-2009, 3:04 PM
    • Member
      14 point Member
    • ronkunce
    • Member since 06-30-2008, 8:28 PM
    • Posts 31

     I don't know much about LINQ, but you could put your two SELECT statement into single stored procedure and retrieve them both into a .net dataset as table(0) and table(1). 

    Ron K.
    ------------------------------
    The secret to creativity is how well you hide your sources -- Albert Einstein
  • Re: Getting two Outputs from same Stored Procedure

    07-06-2009, 3:19 PM
    • Member
      54 point Member
    • splitterside
    • Member since 06-26-2009, 11:12 AM
    • Posts 35

    That might work, but I am not sure how to do that using the statements that I currently have.

  • Re: Getting two Outputs from same Stored Procedure

    07-06-2009, 4:24 PM
    Answer
    • Member
      54 point Member
    • splitterside
    • Member since 06-26-2009, 11:12 AM
    • Posts 35

    I figured it out. I used an output parameter and just referenced the variable with the parameter.

Page 1 of 1 (4 items)