how to get result of last ran query?

Answered how to get result of last ran query?

  • Monday, March 05, 2012 6:51 AM
     
     
    how to get result of last ran query?

    .Net

    • Moved by Papy Normand Saturday, April 07, 2012 2:09 PM Related to the use of the INSERT statement not to a specific feature of SQL Server Express (From:SQL Server Express)
    •  

All Replies

  • Monday, March 05, 2012 10:34 AM
     
     

    Could you provide a little more detail please? What is it that you have done and are trying to do?

    I am assuming that running the same query again and exporting the results are not an option here?

    There are some third party products such as TOAD for SQL Server that will cache result sets so that you can run the same query multiple times and see how the results differ.


    If you find this helpful, please mark the post as helpful,
    If you think this solves the problem, please propose or mark it an an answer.

    Please provide details on your SQL Server environment such as version and edition, also DDL statements for tables when posting T-SQL issues

    Richard Douglas
    My Blog: Http://SQL.RichardDouglas.co.uk
    Twitter: @SQLRich

  • Tuesday, March 06, 2012 5:02 AM
     
     

    In a stored procedure, I have multiple insert statements in separate Try-Catch block.

    Now, I have a log table in which i am maintaining the result of these insert statements whether successful OR failed.

    Now, for the failed operations I  am getting the information from the below statement.

    SELECT  @ErrorNumber = ERROR_NUMBER(),
                    @ErrorSeverity = ERROR_SEVERITY(),
                    @ErrorState = ERROR_STATE(),
                    @ErrorProcedure = ERROR_PROCEDURE(),
                    @ErrorLine = ERROR_LINE(),
                    @ErrorMessage = ERROR_MESSAGE();

    But for the successful insert operations, I am not able to capture the message to insert in the log table.

    kindly help.


    .Net

  • Thursday, March 15, 2012 4:19 PM
     
     Answered

    The INSERT statement now supports an OUTPUT clause, so you can see what data was inserted.


    If you find this helpful, please mark the post as helpful,
    If you think this solves the problem, please propose or mark it an an answer.

    Please provide details on your SQL Server environment such as version and edition, also DDL statements for tables when posting T-SQL issues

    Richard Douglas
    My Blog: Http://SQL.RichardDouglas.co.uk
    Twitter: @SQLRich

  • Wednesday, April 04, 2012 11:04 AM
     
     

    How to achive that?


    .Net

  • Wednesday, April 04, 2012 11:12 AM
     
     
    It's fully documented in Books Online. If you still have a problem after reading it, please feel free to ask for more help.

    If you find this helpful, please mark the post as helpful,
    If you think this solves the problem, please propose or mark it an an answer.

    Please provide details on your SQL Server environment such as version and edition, also DDL statements for tables when posting T-SQL issues

    Richard Douglas
    My Blog: Http://SQL.RichardDouglas.co.uk
    Twitter: @SQLRich

  • Saturday, April 07, 2012 2:07 PM
     
     

    Hi Priyank,

    Richard was referencing

    http://msdn.microsoft.com/en-us/library/ms174335(SQL.100).aspx 

    and http://msdn.microsoft.com/en-us/library/dd776381(SQL.100).aspx 

    you have an example near the end of the page in the part "Capturing the results of the INSERT statements"

    As it is not related to specific features of SQL Server Express , i move this thread towards the TRANSACT-SQL Forum where it will interest more people.

    Have a nice day


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.