Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2003
    Posts
    49

    Unanswered: How To Get A Sql Statement In Query Analyzer

    I am trying to troubleshoot some high activity on one of my SQL Servers, and when I run sp_who2 'active' I get the current activity, and spid number. I check under Process Info for the spid, and wHEN i double click the spid, I get part of the sql statement run by that trouble spid. Is there a way to get the whole sql statement in Query Analyzer without running SQL Profiler. Thanks in advance for any help.

  2. #2
    Join Date
    Apr 2004
    Location
    Kansas City, MO
    Posts
    734
    dbcc inputbuffer(spid)
    MeanOldDBA
    derrickleggett@hotmail.com
    When life gives you a lemon, fire the DBA.

  3. #3
    Join Date
    Sep 2003
    Posts
    49

    Getting Full Sql Statement In Query Analyzer

    Thanks for the help. I tested the command, but it only showed a certain amount of the sql statement. I am running some very long sql statements, and I wanted to know if there was another way to get all of the sql statement no matter the length of the statement for a particular spid. Thanks again for the help.

  4. #4
    Join Date
    Apr 2004
    Posts
    3
    You can use the fn_get_sql function.

    Example From BOL:

    DECLARE @Handle binary(20)
    SELECT @Handle = sql_handle FROM sysprocesses WHERE spid = 52
    SELECT * FROM ::fn_get_sql(@Handle)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •