how to find out the sp query in the middle of execution

  • Hi,

    i 'm having sp. it consits of update,select, insert query. i have executed this sp with parameter.

    example: sp_name : exec abc '03/15/2011'

    I just want to know, which query is executing in this sp.

    i used to print ''.. but it shows the same output.. exec abc '03/15/2011' result only.

    i don't want that result.

    Could anyone knows, help me

    Regards

    Balaji G

  • You will need to either put "breaks" into the stored procedure or run the statements separately.

  • You can get this via fn_get_sql (if you have the right SP, it's one of the hotfixes on sp2 or included in SP3). You can also use profiler.

    http://phelabaum.com/archive/2010/03/dbcc-inputbuffer-vs-fn-get-sql/[/url]

    If you're on 2005 or later, you can get this info via DMV's.

    Seth Phelabaum


    Consistency is only a virtue if you're not a screwup. 😉

    Links: How to Post Sample Data[/url] :: Running Totals[/url] :: Tally Table[/url] :: Cross Tabs/Pivots[/url] :: String Concatenation[/url]

  • here's some code what I pinched from somewhere -

    --How to isolate the current running commands in SQL Server. This query isolates the SQL in the batch

    -- actually running at this point rather than the last command to execute

    SELECT SDER.[session_id], SDER.[request_id],SDER.[statement_start_offset],

    SDER.[statement_end_offset],

    CASE

    WHEN SDER.[statement_start_offset] > 0 THEN

    --The start of the active command is not at the beginning of the full command text

    CASE SDER.[statement_end_offset]

    WHEN -1 THEN

    --The end of the full command is also the end of the active statement

    SUBSTRING(DEST.TEXT, (SDER.[statement_start_offset]/2) + 1, 2147483647)

    ELSE

    --The end of the active statement is not at the end of the full command

    SUBSTRING(DEST.TEXT, (SDER.[statement_start_offset]/2) + 1, (SDER.[statement_end_offset] - SDER.[statement_start_offset])/2)

    END

    ELSE

    --1st part of full command is running

    CASE SDER.[statement_end_offset]

    WHEN -1 THEN

    --The end of the full command is also the end of the active statement

    RTRIM(LTRIM(DEST.[text]))

    ELSE

    --The end of the active statement is not at the end of the full command

    LEFT(DEST.TEXT, (SDER.[statement_end_offset]/2) +1)

    END

    END AS [executing statement],

    DEST.[text] AS [full statement code]

    FROM sys.[dm_exec_requests] SDER CROSS APPLY sys.[dm_exec_sql_text](SDER.[sql_handle]) DEST

    WHERE SDER.session_id > 50

    ORDER BY SDER.[session_id], SDER.[request_id]

    ---------------------------------------------------------------------

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply