Solved

finding recently run statements

Posted on 2011-02-16
5
216 Views
Last Modified: 2012-05-11
i had run some recent statement from query window.. but i am trying to track exact parameters i sent.. but i could not see it from the below query..

there are a bunch of statements even from a week before- so i know memory is not the issue.. what am i missing.. isn't every select and execute statement cached?

thanks
SELECT  text,last_execution_time
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) qt
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp
WHERE last_execution_time between 
'2011-02-16 13:00:00.000' and '2011-02-16 14:45:00.000'
and text like '%sp_send_dbmail%'
ORDER BY qs.last_execution_time DESC

Open in new window

0
Comment
Question by:anushahanna
  • 3
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
lcohan earned 500 total points
ID: 34910957
I believe not all statements will stay in cache forever even if lets say you have infinite memory.
If you look in particular for your sent mail please run following

select * from msdb..sysmail_unsentitems

select top 100 * from msdb..sysmail_sentitems order by sent_date desc
0
 
LVL 39

Expert Comment

by:lcohan
ID: 34911006
Or just run this without date limit:

SELECT  top 100 text,last_execution_time
      FROM sys.dm_exec_query_stats qs
            CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) qt
            CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp
      WHERE text like '%sp_send_dbmail%'
      ORDER BY qs.last_execution_time DESC
0
 
LVL 6

Author Comment

by:anushahanna
ID: 34935856
lcohan, still could not get it.. even though there is entry from before when these were written. do this come under your category you mentioned "I believe not all statements will stay in cache"- if so, what might they be?
0
 
LVL 39

Assisted Solution

by:lcohan
lcohan earned 500 total points
ID: 34954707
Sorry I created more confusion than helped. Here, please run the query below and have a look at the creation_date vs. last_execution_time. They will be different for objects planned and stored in cache at the creation_time and last executed on last_execution_time - this should be pretty strait forward.
The objects you see with old creation_time were planned/stored in cache since and what I'm trying to say is that not ALL objects will stay in cache forever or for for the same duration. You could see the query plan if you click the link on the last column.

SELECT top 100 text,creation_time,last_execution_time,query_plan
    FROM sys.dm_exec_query_stats qs
       CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) qt
       CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) qp

Now, if you look in particular for "sp_send_dbmail" queries then you could find all sent/unsent mail info in the two: msdb..sysmail_unsentitems and msdb..sysmail_sentitems
0
 
LVL 6

Author Comment

by:anushahanna
ID: 34985881
thanks lcohan- for your detailed query.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now