Results 1 to 3 of 3
  1. #1
    Join Date
    May 2008
    Posts
    1

    Unanswered: Retrieve used queries

    Hello

    Is it possible to retrieve queries that an application used to get data out of my sql-server. (variables included).

    Thanks

    Rene

  2. #2
    Join Date
    Aug 2004
    Location
    Dallas, Texas
    Posts
    831
    Quote Originally Posted by renejola View Post
    Hello

    Is it possible to retrieve queries that an application used to get data out of my sql-server. (variables included).

    Thanks

    Rene
    Try using profiler. Save results into a table and then analyze.

  3. #3
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    I am sure I posted it here at least once, but here's another version:
    Code:
    declare @path        nvarchar(1024)
           ,@pattern     nvarchar(10)
           ,@replacement nvarchar(10)
           ,@firstfile   nvarchar(1024)
    select @path = [path] from sys.traces where is_default = 'true'
    set @pattern = reverse(substring(reverse(@path), 1, charindex(N'_', reverse(@path))))
    if cast(replace(replace(@pattern, N'_', N''), N'.trc', N'') as int) <= 4
       set @replacement = N'_1.trc'
    else
       set @replacement = N'_' + cast(cast(replace(replace(@pattern, N'_', N''), N'.trc', N'') as int) - 4 as nvarchar(10)) + N'.trc'
    set @firstfile = replace(@path, @pattern, @replacement)
    select * from ::fn_trace_gettable(@firstfile, 0)
    Last edited by rdjabarov; 01-19-11 at 18:10. Reason: changed from < 4 to <= 4
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

Posting Permissions

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